This is a migrated thread and some comments may be shown as answers.

Problem with multiple main windows on different threads

3 Answers 43 Views
Window
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 2
Veteran
Iron
Patrick asked on 30 Apr 2016, 04:27 AM

Hello,

I have a program that, each time I open a new file on it creates a new main window on its own thread.

Everything is working OK, except on the following scenario:

  1. A file in opened in the application main window.
  2. A second file is opened in a new main window.
  3. In this second main window, a RadWindow is opened.
  4. The RadWindow is moved.

At this time, the application crashes with the following exception and stack trace:

The calling thread cannot access this object because a different thread owns it.    Exception {InvalidOperationException}

     WindowsBase.dll!System.Windows.Threading.Dispatcher.VerifyAccess()    Unknown
     PresentationFramework.dll!System.Windows.Application.MainWindow.get()    Unknown
     Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.InternalWindow.ChromelessWindowHelper.GetDpiIndependentPrimaryScreenSize()    Unknown
     Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.InternalWindow.ChromelessWindowHelper.HandleGetMinMaxInfo(System.IntPtr hwnd = {System.IntPtr}, System.IntPtr wParam = {System.IntPtr}, System.IntPtr lParam = {System.IntPtr}, out bool handled = false)    Unknown
     Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.InternalWindow.ChromelessWindowHelper.WndProc(System.IntPtr hwnd = {System.IntPtr}, int msg = 36, System.IntPtr wParam = {System.IntPtr}, System.IntPtr lParam = {System.IntPtr}, ref bool handled = false)    Unknown
     PresentationCore.dll!System.Windows.Interop.HwndSource.PublicHooksFilterMessage(System.IntPtr hwnd = {System.IntPtr}, int msg, System.IntPtr wParam = {System.IntPtr}, System.IntPtr lParam = {System.IntPtr}, ref bool handled = false)    Unknown
     WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd = {System.IntPtr}, int msg, System.IntPtr wParam = {System.IntPtr}, System.IntPtr lParam = {System.IntPtr}, ref bool handled = false)    Unknown
     WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)    Unknown
     WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)    Unknown
     WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source = {System.Windows.Threading.Dispatcher}, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler = null)    Unknown
     WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)    Unknown
     WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd = {System.IntPtr}, int msg, System.IntPtr wParam = {System.IntPtr}, System.IntPtr lParam = {System.IntPtr})    Unknown
     [Native to Managed Transition]    
     [Managed to Native Transition]    
     WindowsBase.dll!MS.Win32.HwndSubclass.DefWndProcWrapper(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)    Unknown
     [Native to Managed Transition]    
     [Managed to Native Transition]    
     WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)    Unknown
     [Native to Managed Transition]    
     [Managed to Native Transition]    
     WindowsBase.dll!MS.Win32.HwndSubclass.DefWndProcWrapper(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)    Unknown
     [Native to Managed Transition]    
     [Managed to Native Transition]    
     WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)    Unknown
     [Native to Managed Transition]    
     [Managed to Native Transition]    
     WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame = {System.Windows.Threading.DispatcherFrame})    Unknown
     PresentationFramework.dll!System.Windows.Window.ShowHelper(object booleanBox)    Unknown
     PresentationFramework.dll!System.Windows.Window.ShowDialog()    Unknown
     Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.InternalWindow.WindowWithNoChromeWindowHost.Open(bool isModal = true)    Unknown
     Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.WindowBase.ShowWindow(bool isModal = true)    Unknown
     Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadWindow.ShowDialog()    Unknown

 

Note that doing the same on the first main window doesn't crash the application.

3 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 04 May 2016, 08:05 AM
Hi Patrick,

From the provided stack trace it seems the exception is thrown because you are creating an instance of the RadWindow on different thread which cause a cross threading issue.However, due to the lack of information about your implementation and scenario we could tell for sure if that is really the case and because of that we could not provide you with a solution.

Please, try to isolate the issue in a sample project and send it to us - thus we could be able to observe it on our side as well and will try to provide you with a prompt solution.

We are looking forward to hearing from you.


Regards,
Nasko
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Patrick
Top achievements
Rank 2
Veteran
Iron
answered on 17 May 2016, 08:55 AM

Hi Nasko,

I've just tested with 2016 R2 version of Telerik UI for WPF and the problem is no more here... As I didn't change anything on the project in between, the problem is surely a bug in the Telerik library that has been corrected.

0
Nasko
Telerik team
answered on 17 May 2016, 11:03 AM
Hello Patrick,

I am glad to hear your issue has been resolved and you are no longer observing an exception.

If you have any additional questions or concerns regarding Telerik controls, please let us know.

Regards,
Nasko
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
Window
Asked by
Patrick
Top achievements
Rank 2
Veteran
Iron
Answers by
Nasko
Telerik team
Patrick
Top achievements
Rank 2
Veteran
Iron
Share this question
or