This is a migrated thread and some comments may be shown as answers.
Using RadGrid in other thread
1 Answer 28 Views
This is a migrated thread and some comments may be shown as answers.
FAUSTO
Top achievements
Rank 1
FAUSTO asked on 25 Jun 2014, 03:08 PM
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.

1 Answer, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 26 Jun 2014, 08:14 AM
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.
 
Asked by
FAUSTO
Top achievements
Rank 1
Answers by
Nick
Telerik team
Share this question
or