Calling thread Exception while floating a tool window from UI thread other then Main thread

Docking/MDI for WPF Forum

Posted 11 years ago by keshav bansal
Version: 13.1.0583
Avatar

Hi,

We have a requirement to open two windows in different UI threads.

Suppose,

X Window opens in Main thread

Y window opens in another thread

Now we have a tool window in both X window and Y window.

While we are trying to float the tool window programtaically in Y window using "toolWindow.Float()" we are getting following exception.When we tried to float the toolwindow in X window, it works fine with toolWindow.Float().Also the same error threading errors occurs when we double click on the Y Window toolWindow.

Please suggest any solution for this problem as this is becoming a Show Stopper issue for our application. Your help is highly appreciable. Waiting for your earliest response.

 

System.InvalidOperationException was unhandled
Message=The calling thread cannot access this object because a different thread owns it.
Source=WindowsBase
StackTrace:
at System.Windows.Threading.Dispatcher.VerifyAccess()
at #Ci.#Bi.#1z(Window #sb)
at #Ci.#Bi.#0z(Rect #Bo)
at ActiproSoftware.Windows.Controls.Docking.Primitives.RaftingWindow.SnapToScreen()
at ActiproSoftware.Windows.Controls.Docking.DockSite.#Tt(#ki #4j, DependencyObject #lp, Nullable'1 #2cc, Nullable'1 #xe, FloatSizingBehavior #dFf, Boolean #cFf)
at ActiproSoftware.Windows.Controls.Docking.DockSite.#St(DependencyObject #lp, Nullable'1 #2cc, Nullable'1 #xe, FloatSizingBehavior #dFf, Boolean #cFf)
at ActiproSoftware.Windows.Controls.Docking.DockSite.#St(DependencyObject #lp, Nullable'1 #2cc, FloatSizingBehavior #dFf, Boolean #cFf)
at ActiproSoftware.Windows.Controls.Docking.Primitives.RaftableDockingWindowContainer.Float(FloatSizingBehavior behavior)
at ActiproSoftware.Windows.Controls.Docking.Primitives.RaftableDockingWindowContainer.#Gq(Object #xhb, MouseButtonEventArgs #yhb)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at DockingApplication.OpenNewThreadTW.Open() in D:\DockingApplication\DockingApplication\OpenNewThreadTW.xaml.cs:line 43
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: 

Comments (1)

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Keshav,

Any time you access UI in WPF, it must be on the same dispatcher thread that it was created on.  If you have the Dispatcher of the target UI element, you can call methods like Dispatcher.Invoke and pass them a lambda expression with the code to execute on that dispatcher thread.  That prevents the issue and there is documentation on that sort of thing on the web.

As for the double click on the tool window title bar, I'm not sure what is causing that.  You'd need to send in a very simple sample project showing it to our support address so we can debug it.  Please reference this post and rename the .zip file extension so it doesn't get spam blocked.


Actipro Software Support

The latest build of this product (v24.1.3) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.