Problem with multiple main windows on different threads

4 posts, 0 answers
  1. Patrick
    Patrick avatar
    372 posts
    Member since:
    Aug 2012

    Posted 29 Apr Link to this post

    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.

  2. Nasko
    Admin
    Nasko avatar
    585 posts

    Posted 04 May Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Patrick
    Patrick avatar
    372 posts
    Member since:
    Aug 2012

    Posted 17 May in reply to Nasko Link to this post

    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.

  5. Nasko
    Admin
    Nasko avatar
    585 posts

    Posted 17 May Link to this post

    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.
Back to Top