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

Error with updating RadGridView data in different threads

13 Answers 154 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sergey
Top achievements
Rank 1
Sergey asked on 20 Mar 2014, 07:17 AM
Hello.

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

Sort by
0
Sergey
Top achievements
Rank 1
answered on 20 Mar 2014, 08:01 AM
I think the error happen when I'm using column sorting (decimal). I wrote this code to apply sorting in real time because I don't replace full updating object:

_accountMarginListCollection[index] = _accountMarginListCollection[index];
0
Yordanka
Telerik team
answered on 20 Mar 2014, 12:27 PM
Hi Sergey,

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.

 
0
Sergey
Top achievements
Rank 1
answered on 27 Mar 2014, 01:02 PM
Hello. I try to setup a sample project . (http://files.mail.ru/84FB3CDADF3C4E0DB34A767C2BC6E888)

But I couldn't reproduce the same error in this small sample project. But I reproduced another error (very close).
0
Sergey
Top achievements
Rank 1
answered on 27 Mar 2014, 01:37 PM
I found another interesting things. I clicked on a column header to set sorting. After that I tried to add the first row in the RadObservableCollection in non UI-thread and got a error (see attached files in the first post). Then I clicked the column header again to delete sorting and I saw my row.

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.
0
Sergey
Top achievements
Rank 1
answered on 28 Mar 2014, 01:01 PM
It's very important for me (We develop a trade application and our clients have these errors)! Solve my problem, please.
0
Dimitrina
Telerik team
answered on 28 Mar 2014, 03:26 PM
Hi,

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.

 
0
Sergey
Top achievements
Rank 1
answered on 28 Mar 2014, 04:31 PM
I know that I can write adding code in UI dispatcher (I did that). But it reduces application performance (But in trading application performance is very important). And the error only happen with sorting. Is there a way to add rows on non Ui-thread? 

I use 2013.3.1016.40.NoXaml. Maybe in latest version it will be better?
0
Sergey
Top achievements
Rank 1
answered on 28 Mar 2014, 04:35 PM
Sometimes  adding row works fine with sorting. I can't find difference between situations
0
Sergey
Top achievements
Rank 1
answered on 30 Mar 2014, 06:08 PM
Or can you give me the best way to update collection from non UI-thread (for 1 row and for many rows).

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)
0
Sergey
Top achievements
Rank 1
answered on 30 Mar 2014, 06:09 PM
Edit: the best way with the best performance
0
Sergey
Top achievements
Rank 1
answered on 31 Mar 2014, 10:54 AM
I found that adding the first row must be in UI-thread. The other rows I can add in non Ui-thread. (When radGridView has sorting or filters)
0
Dimitrina
Telerik team
answered on 01 Apr 2014, 01:24 PM
Hello,

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.

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.

 
0
Yordanka
Telerik team
answered on 16 Apr 2014, 01:45 PM
Hi Sergey,

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.

 
Tags
GridView
Asked by
Sergey
Top achievements
Rank 1
Answers by
Sergey
Top achievements
Rank 1
Yordanka
Telerik team
Dimitrina
Telerik team
Share this question
or