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

Cannot access a disposed object

3 Answers 831 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hannah
Top achievements
Rank 2
Hannah asked on 14 Jun 2013, 05:13 PM
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.

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 19 Jun 2013, 02:49 PM
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?
0
Hannah
Top achievements
Rank 2
answered on 24 Jun 2013, 11:20 PM
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
0
Peter
Telerik team
answered on 27 Jun 2013, 04:51 PM
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 >>
Tags
GridView
Asked by
Hannah
Top achievements
Rank 2
Answers by
Peter
Telerik team
Hannah
Top achievements
Rank 2
Share this question
or