Error with updating RadGridView data in different threads

14 posts, 0 answers
  1. Sergey
    Sergey avatar
    58 posts
    Member since:
    Jan 2013

    Posted 20 Mar 2014 Link to this post

    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.
  2. Sergey
    Sergey avatar
    58 posts
    Member since:
    Jan 2013

    Posted 20 Mar 2014 in reply to Sergey Link to this post

    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];
  3. Yordanka
    Admin
    Yordanka avatar
    634 posts

    Posted 20 Mar 2014 Link to this post

    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.

     
  4. Sergey
    Sergey avatar
    58 posts
    Member since:
    Jan 2013

    Posted 27 Mar 2014 in reply to Yordanka Link to this post

    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).
  5. Sergey
    Sergey avatar
    58 posts
    Member since:
    Jan 2013

    Posted 27 Mar 2014 in reply to Yordanka Link to this post

    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.
  6. Sergey
    Sergey avatar
    58 posts
    Member since:
    Jan 2013

    Posted 28 Mar 2014 Link to this post

    It's very important for me (We develop a trade application and our clients have these errors)! Solve my problem, please.
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 28 Mar 2014 Link to this post

    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.

     
  8. Sergey
    Sergey avatar
    58 posts
    Member since:
    Jan 2013

    Posted 28 Mar 2014 in reply to Dimitrina Link to this post

    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?
  9. Sergey
    Sergey avatar
    58 posts
    Member since:
    Jan 2013

    Posted 28 Mar 2014 Link to this post

    Sometimes  adding row works fine with sorting. I can't find difference between situations
  10. Sergey
    Sergey avatar
    58 posts
    Member since:
    Jan 2013

    Posted 30 Mar 2014 Link to this post

    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)
  11. Sergey
    Sergey avatar
    58 posts
    Member since:
    Jan 2013

    Posted 30 Mar 2014 Link to this post

    Edit: the best way with the best performance
  12. Sergey
    Sergey avatar
    58 posts
    Member since:
    Jan 2013

    Posted 31 Mar 2014 in reply to Sergey Link to this post

    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)
  13. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 01 Apr 2014 Link to this post

    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.

     
  14. Yordanka
    Admin
    Yordanka avatar
    634 posts

    Posted 16 Apr 2014 Link to this post

    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.

     
Back to Top