Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2006

Tip: Looking for answers? Try searching our database.

?!?ParkingWindow - ObjectDisposedException in system.windows.forms

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sigrun - 07 Feb 2006 16:28 GMT
Hello.
Im programming a Windows Forms application that has many user controls (e.g.
charts).  These user controls have System.Threading.TimerCallback functions.  
These functions Invoke other member methods that update the user controls
e.g.:

private void OnTimerUpdate(object pState)
{
if( mMainChart.InvokeRequired )
{
    Invoke(new UpdateAndCleanUpChartDelegate(UpdateAndCleanUpChart));
}
else
{
    UpdateAndCleanUpChart();
}
}

After calling Application.Exit() I get a bunch of message boxes with the
following messages:

System.ObjectDisposedException: Cannot access a disposed object named
"ParkingWindow".
Object name: "ParkingWindow".
  at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate
method, Object[] args, Boolean synchronous)
  at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
  at System.Windows.Forms.Control.Invoke(Delegate method)
  at MyChartClass.OnTimerUpdate(Object pState)An unhandled exception of
type 'System.ObjectDisposedException' occurred in system.windows.forms.dll

Additional information: Cannot access a disposed object named "ParkingWindow".

This happens randomly, i.e. for different user controls each time.

Could anyone help me out here, how do I prevent this or handle the problem.
Regards,
Stoitcho Goutsev (100) - 07 Feb 2006 17:43 GMT
Sigrun,

You need to stop those timers before closing the application. It looks like
they fire events that you try to marshal to the UI thread while the controls
are being disposed.

Keep in mind that depending on the timer you may receive tick after shuting
down the timer. You need to handle these situations and not to try
marshaling the call. You can use for example Control's Disposing and
Disposed properties before calling InvokeRequired and Invoke

Signature

HTH
Stoitcho Goutsev (100)

> Hello.
> Im programming a Windows Forms application that has many user controls
[quoted text clipped - 37 lines]
> problem.
> Regards,
Peter Bromley - 07 Feb 2006 22:31 GMT
> Sigrun,
>
[quoted text clipped - 6 lines]
> marshaling the call. You can use for example Control's Disposing and
> Disposed properties before calling InvokeRequired and Invoke

 Actually, its worse than that, because the object may not be disposed
or disposing when you call Invoke and be disposed by the time the
message pump attempts to dispatch the Invoke (and generates the exception)

What I do is try/catch the Invoke call and swallow any
ObjectDisposedException that is generated.

C++ code:

try
    {
    Invoke(...)
    }
catch (System::ObjectDisposedException* ex)
    {}

HTH.
Sigrun - 08 Feb 2006 11:19 GMT
Thenk you Peter and Stoitcho.
This was useful to me, I have added a check of the disposing property, if
the object is not disposing, I go through the Invoke phase using try-catch.
This handles the problem.  It would be nice if someone from Microsoft would
point out how to AVOID the problem though.
rgds
Sigrún

> > Sigrun,
> >
[quoted text clipped - 24 lines]
>
> HTH.
Dmytro Lapshyn [MVP] - 08 Feb 2006 11:24 GMT
As an MVP, I would like to recommend Microsoft that a KB article be created
explaining this situation.

> Thenk you Peter and Stoitcho.
> This was useful to me, I have added a check of the disposing property, if
[quoted text clipped - 38 lines]
>>
>> HTH.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.