I have some problem with using RadGridView. My application add, delete or update GridView data in real time. It happens in different threads. And some times I get a error (see attached files). It's very important for me. Thanks.
13 Answers, 1 is accepted
_accountMarginListCollection[index] = _accountMarginListCollection[index];
Could you try setup a sample project which reproduce the exception? Once we reproduce it locally we will debug it and will assist you further. In order to attach a project please open a support ticket. Thank you in advance.
Regards,
Yordanka
Telerik
Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.
But I couldn't reproduce the same error in this small sample project. But I reproduced another error (very close).
And I can reproduce the error in my test project (which I sent in previous post). You need to add <Setter Property="GroupRenderMode" Value="Flat"/> to radGridView and add sorting before click the "Start" button.
I checked the attached solution. You will need to ensure that the Add operations are executed fine.
For the purpose you need to invoke your code in a Dispatcher.
Task.Factory.StartNew(() =>
{
try
{
Application.Current.Dispatcher.BeginInvoke(
new
Action(() =>
{
_openBookCollection.Add(
new
OpenBookItem() { Price = _rnd.Next(0, 100) });
_openBookCollection[0] = _openBookCollection[0];
}));
}
...
I also tested configuring RadGridView as you suggested and adding Sorting for the column before pressing the "Start" button. As a result, the suggested code also worked fine in this case.
I hope this helps.
Regards,
Didie
Telerik
Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.
I use 2013.3.1016.40.NoXaml. Maybe in latest version it will be better?
Now, I write this code:
_collection.SuspendNotification();
foreach()
{
_collection.Add(new object()); (or update line)
}
DispatcherUI.Invoke(() => _collection.ResumeNotification()); (Sometimes I don't need to write this code in UI-thread. Why? how can I check that I need to write the method with Invoke on UI-thread)
The error message states:
The calling thread cannot access this object because a different thread owns it.
This seems to be a general problem, rather than a problem specific to RadGridView (with sorting or filtering applied).
Generally when you update your UI elements from a thread other than the main thread, you need to use:
this.Dispatcher.Invoke((Action)(()=>{...// your code here.}));
so that to ensure the operation will be executed correctly.
You can also use control.Dispatcher.CheckAccess() to check whether the current thread owns the control. If it does own it, your code should work fine. Otherwise, you can use above pattern.
Please note the Dispatcher.Invoke method executes the specified delegate synchronously on the thread the Dispatcher is associated with.
Didie
Telerik
Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.
We investigated the error you reported initially and found it is a bug in our code. Fortunately, we managed to resolve it. The fix for it will be included in the next internal build. It will be available for downloading on Monday.
Thank you once again for the report.
Regards,
Yordanka
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.