By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,854 Members | 1,912 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,854 IT Pros & Developers. It's quick & easy.

RichTextBox on Form -- Exception.. Cannot access a disposed object

P: n/a
I have a C# MDI app. The child forms do alot of work, so this work is
perfomed on a different thread created using ThreadPool.QueueUserWorkItem().
Because the status of the work is important to the user, I post the results
in a richTextBox on the child form. I have created an event to do this since
it is best to update the controls using the thread that they were created
with (or so I've read).

Anyway, the first time the user selects a form and starts the work (pushes
start button), everything is fine. However, if the user closes the form and
then reopens it and restarts the test, the following exception is thrown ...
"System.ObjectDisposedException" ... "Cannot access a disposed object named

The child form is created using this code...
private void menuItemTestMultiple_Click(object sender, System.EventArgs e)
dlgDATestMult = new MultiplePass(ParentWindow);

The richTextBox I speak of was created using the forms designer.

Any ideas?

Thanks in advance
Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies

P: n/a
> "System.ObjectDisposedException" ... "Cannot access a disposed object

Perhaps your thread is trying to access the RichTextBox on the old form?
If the old form was closed and disposed, you would need to update the
RichTextBox reference in the thread.

Nov 17 '05 #2

P: n/a
Thanks for your quick reply...

I'm kinda new to this C# thing, but isn't a new instance of the form class
created each time the "new" keyword is used? If so, wouldn't that mean that
the richTextBox that is created the second time the user selected to open it
is a different text box than the first time?

If not, how do I make it different?

Thanks again

Nov 17 '05 #3

P: n/a
Hi mthgk,

Yes, as you assumed, each time the new keyword is used, a new instance of
the object is created. So the RichTextBox object in the new child form is
also another instance. As Wessel suggested, you need to update the
reference to RichTextBox in the working thread.

Kevin Yu
"This posting is provided "AS IS" with no warranties, and confers no

Nov 17 '05 #4

P: n/a
Ah...........the lightbulb finally came on.... I wasn't using the "this"
keyword when invoking the event. Thanks for your help

-- mthgk
Nov 17 '05 #5

P: n/a
Nice to hear that you have had the problem resolved.

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
"This posting is provided "AS IS" with no warranties, and confers no

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.