Cannot access a disposed object

4 posts, 0 answers
  1. Hannah
    Hannah avatar
    37 posts
    Member since:
    May 2013

    Posted 14 Jun 2013 Link to this post

    Error:  Cannot access a disposed object. Object name: 'GridViewSynchronizationService'.

    Scenario: This error only appears to happen when I'm utilizing an EventLogEntryCollection as the datasource and refreshing the datasource via a timer event. The form is a simple event log monitor.

    The error occurs randomly on either of these lines (this is from within a custom control):

    this.dgResults.DataSource = null;
    this.dgResults.DataSource = this.DataCache;

    The above DataCache object is a dynamic property that is populated by the code below.

    EventLog e = new EventLog(EDI.Definitions.EVENT_LOG, ConfigurationManager.AppSettings["EventLogServerName"]);
    this.dgResults.DataSource = e.Entries;

    The above snippet is from a form that is consuming the custom datagrid control (so the dgResults object is distinguishable for anyone reading).

    I can't recreate the issue as it just randomly appears from time to time.

    Hopefully this is a known issue of some type and there is an easy fix.  I saw that clearing the relations might work, but that doesn't seem to be working for me.

    Ideas anyone?  Thanks in advance! Let me know if more is required.

  2. Peter
    Admin
    Peter avatar
    1157 posts

    Posted 19 Jun 2013 Link to this post

    Hi Wayne,

    Thank you for writing.

    This error indicates that the grid is not in valid state. 
    You have mentiond that you update the datasource on timer and I would like to clarify that all UI controls are not thread safe controls in the whole Windows Forms UI platform. Here is an article on MSDN describing how to make thread-safe Winforms UI application. This means that RadGridView is not thread safe as well and cannot be used outside the main UI thread. In case that you are using a Timer from the System.Timers namespace you should know that this runs in the ThreadPool and your application will always produce cross-thread exception in the context of GUI. You should change the Timer object to System.Windows.Forms timer that runs in the same main thread and use it to implement the desired behavior. Also you should use an Invoke to update the controls in cross threading scenario. For example:
    if (gridLogs.InvokeRequired)
    {
        barLog.Invoke(new MethodInvoker(() => { AddEntry("Testing a message iteration:" + i + " of total " + RowCount(), EventLogEntryType.Information); }));
    }
    else
    {
        AddEntry("Testing a message iteration:" + i + " of total " + RowCount(), EventLogEntryType.Information);
    }

    I hope this helps.

    Regards,
    Peter
    Telerik
    RadChart for WinForms is obsolete. Now what?
  3. Hannah
    Hannah avatar
    37 posts
    Member since:
    May 2013

    Posted 24 Jun 2013 Link to this post

    I'm utilizing the Windows.Forms.Timer class, and no extra threads are being created by my code.  I'm continuing to monitor this form for the error and trying to get more information, but the error isn't consistent and I don't have much else to go on at the moment.

    If I find more info, I'll update this thread.

    thanks for the response!

    Wayne
  4. Peter
    Admin
    Peter avatar
    1157 posts

    Posted 27 Jun 2013 Link to this post

    Hello Wayne,

    Thank you for provided details.

    Take your time and when you isolate a pattern which leads to this feel free to write back with additional details.

    Regards,
    Peter
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top