Follow in Twitter & Facebook



Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools



Friday, May 4, 2012

Cannot access a disposed object. Object name:'Form4'

Introduction:
Here we will discuss about one ObjectDisposedException, which i got when i was doing one WindowsFormApplication demo using Vb.Net. The Exception was like "Cannot access a disposed object. Object name:'Form4'".

Description:
Here we will discuss about one Exception i.e "Cannot access a disposed object. Object name:'Form4'", which i got while i was doing one Windows Application demo using Vb.Net.In my demo there was one start button, one Stop button, one Progressbar, one Level, one BackgroundWorker.

When i clicked on start button now it was progressing with the percentage of progressing. With in that i clicked the Stop button then i saw the cancelled message. Then when i again clicked on the Start button , i found that Exception i.e "Cannot access a disposed object. Object name:'Form4'".

I got the error in this line like SetLabelText_ThreadSafe(Me.lbl_Status, FormatPercent(i / m_CountTo, 2)).

For the solution of this exception you need to check first the 'IsDisposed' property of the control before acessing the control.

Otherwise you need to instanciate the form inside the constructor of that form.
Dim frm4 As New Form4()

The screenshot of that Exception, I am sharing now.....




0 on: "Cannot access a disposed object. Object name:'Form4'"