473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

"Cannot access a disposed object"

Hi,

I have a grid which is continuously updating by the data from a external
event. When I close the form on which the grid is placed, then it gives the
error message ...

"Can not access a disposed object".

I understand that it is because as soon as the form is closed it will in
turn try to dispose the grid. I have unwired the event in the dispose of
grid (In which event I get the data) but it doesn't solve the purpose
completely. It is because when the dispose is called for grid, control might
be inside the method (Though I have already check in the start of the method
if the instance of the grid is not null) , where the grid is accessed.
Please tell me, how I can avoid this situation and dispose the grid
properly.

Regards,
Rajat.
Jul 21 '06 #1
2 3591
Is there a stack trace associated with the exception?

"Rajat Tandon" <ra**********@algorismtech.comwrote in message
news:eY**************@TK2MSFTNGP03.phx.gbl...
Hi,

I have a grid which is continuously updating by the data from a external
event. When I close the form on which the grid is placed, then it gives
the
error message ...

"Can not access a disposed object".

I understand that it is because as soon as the form is closed it will in
turn try to dispose the grid. I have unwired the event in the dispose of
grid (In which event I get the data) but it doesn't solve the purpose
completely. It is because when the dispose is called for grid, control
might
be inside the method (Though I have already check in the start of the
method
if the instance of the grid is not null) , where the grid is accessed.
Please tell me, how I can avoid this situation and dispose the grid
properly.

Regards,
Rajat.


Jul 21 '06 #2
I have seen a few causes of this ...

Are you by chance using invoke/begininvoke to move operations to the main
thread from a background thread? If you are you have a race condition .. The
background thread doing the updating looks and the grid is fine, its uses
begininvoke or invoke to send a message to the main thread to do the update.
Both invoke and begininvoke use PostMessage to put a message for the main
thread. While the message sits in the queue the datagrid is disposed. The
main thread then picks up the message from the queue and tries to execute
it. If this is your problem you can work around it by doing the check on the
main thread as opposed to in thge background thread
be inside the method (Though I have already check in the start of the
method
if the instance of the grid is not null) , where the grid is accessed.
Also you say that you are checking that the reference is not null .. the
reference is not null but is pointing to a disposed object (its still a
valid reference and is not null, it has just been told to release anything
internal and is therefore inaccessible)

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung
'
"Rajat Tandon" <ra**********@algorismtech.comwrote in message
news:eY**************@TK2MSFTNGP03.phx.gbl...
Hi,

I have a grid which is continuously updating by the data from a external
event. When I close the form on which the grid is placed, then it gives
the
error message ...

"Can not access a disposed object".

I understand that it is because as soon as the form is closed it will in
turn try to dispose the grid. I have unwired the event in the dispose of
grid (In which event I get the data) but it doesn't solve the purpose
completely. It is because when the dispose is called for grid, control
might
be inside the method (Though I have already check in the start of the
method
if the instance of the grid is not null) , where the grid is accessed.
Please tell me, how I can avoid this situation and dispose the grid
properly.

Regards,
Rajat.


Jul 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Fie Fie Niles | last post by:
I have IIS installed on XP Professional workstation machine. I have an ASP page that open connection to an Access database, then when trying to update the database, it gave me the error "cannot...
7
by: Ryan Park | last post by:
Hi, //SITUATION I got a panel control that hold a certain position on a form. Every controls or UIs are on this panel. At certain situation, I called dispose() method of this panel control...
1
by: n_o_s_p_a__m | last post by:
My web service has a webmethod whose return type is declared as an interface type, for example: public IBusinessProcess GetBusinessProcess() {} which generates the lovely error: Cannot...
1
by: Thomas Barnet-Lamb | last post by:
I was wondering if anyone could give me some help with the following. Consider the code snippet: struct qqq{typedef qqq* pointer;}; template<class al> struct foo : public al { template...
3
by: Karel Vandenhove | last post by:
Hi, I get an error "cannot apply indexing with to an expression of type object" when I try to compile the code below. SSLScannerManager is a COM component. (Used to access fingerprint...
7
by: ed | last post by:
Hi, Here's my code 'in form WithEvents formReplace As New Form Private Sub cmdFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFind.Clic formReplace.Show(
6
by: Aaron Smith | last post by:
Ok. I have a dataset that has multiple tables in it. In one of the child tables, I have a column that I added to the DataSet (Not in the DataSource). This column does not need to be stored in the...
3
by: Ravindra Tripathi | last post by:
Hi I have a form with a textbox and a close button. whenever I try to close the the form i get an exception "cannot access disposed object named" how do i correct this issue? Ravindra
14
by: sarabonn | last post by:
hallo Iam trying to insert a row into a access database using visual c# and iam getting an error " cannot open the action query". here is my code private void button1_Click(object sender,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.