Using RadGrid in other thread

2 posts, 0 answers
  1. FAUSTO
    FAUSTO avatar
    1 posts
    Member since:
    Feb 2014

    Posted 25 Jun 2014 Link to this post

    Hi,
    In my application, I open a modal window in a separate thread with following method:

    public static void ShowInSeparateThread(Type windContent, string windowTitle, int width = 900, int height = 700)
            {
                var _viewerThread = new Thread(delegate()
                {
                    var _eventAggregg = ServiceLocator.Current.GetInstance<IEventAggregator>();
     
                    _eventAggregg.GetEvent<ShowModalPopUp>().Publish(true);
     
                    var _win = new Window
                    {
                        Title = windowTitle,
                        DataContext = new WindowDataContext(),
                        WindowStartupLocation = WindowStartupLocation.CenterScreen,
                        WindowStyle = WindowStyle.None,
                        Style = Application.Current.FindResource("PopUpWindowStyle") as Style,
                        Padding = new Thickness(0),
                        Margin = new Thickness(0),
                        ResizeMode = ResizeMode.NoResize,
                        Content = ServiceLocator.Current.GetInstance(windContent),
                        Width = width,
                        Height = height,
                        ShowInTaskbar = false
                    };
     
                   typeof(Window)
                        .InvokeMember("_ownerHandle",
                            BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField,
                            null, _win, new object[] { Process.GetCurrentProcess().MainWindowHandle });
     
                    _win.ShowDialog();
                    _eventAggregg.GetEvent<ShowModalPopUp>().Publish(false);
                })
                {               
                    IsBackground = true
                };
                _viewerThread.SetApartmentState(ApartmentState.STA);
                _viewerThread.Start();
            }
        }



    In this window i navigate some user controls. One of that user controls contains a RadGridView binded to an ObservableCollection. When I add an item to ObservableCollection the grid items are properly notified, but when I try to remove an item from ObservableCollection i receive

    The calling thread cannot access this object because a different thread owns it.

    If try to change the RadGridView with native DataGrid and all works correctly. I tried also with Dispatcher.Invoke but this approach not solve my problem.

    Thanks in advance for Help.
  2. Nick
    Admin
    Nick avatar
    593 posts

    Posted 26 Jun 2014 Link to this post

    Hello Fausto,

    This seems very strange. The Dispatcher invocation of the CRUD operations should fix the problem. It seems this may be something entirely different. Unfortunately I cannot say what goes wrong, judging by the code snippet you have provided. Will it be possible to open a support ticket and send a small sample that we can debug, in order to determine the cause of the issue, and find a solution in the shortest terms?

    Thank you in advance. 

    Regards,
    Nik
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top