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
"RichTextBox".".
The child form is created using this code...
private void menuItemTestMultiple_Click(object sender, System.EventArgs e)
{
dlgDATestMult = new MultiplePass(ParentWindow);
dlgDATestMult.Show();
}
The richTextBox I speak of was created using the forms designer.
Any ideas?
Thanks in advance
--
--mthgk 5 6021
> "System.ObjectDisposedException" ... "Cannot access a disposed object named "RichTextBox".".
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.
Greetings,
Wessel
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
--mthgk
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
rights."
Ah...........the lightbulb finally came on.... I wasn't using the "this"
keyword when invoking the event. Thanks for your help
-- mthgk
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
rights." This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: D Witherspoon |
last post by:
I use the following code to open up a form.
-------------------------------------------------------
If fImage Is Nothing Then
fImage = New frmImage
End If
fImage.Show()
|
by: Muscha |
last post by:
Hello,
Every now and then my application throw this exception:
"Unable to read data from the transport connection"
And when I break into the Visual Studio, the thread where it failed has...
|
by: KenH |
last post by:
I am getting an unhandled system exception while writing to a RichTextBox. The process may run for a few hours or days before the error is generated
The message is "Cannot access a disposed object...
|
by: Nathan Carroll |
last post by:
In an mdi environment I constructed a child for with a richtextbox control
that is used to load .rtf's. This works fine on the intiatial load of the
form but when for is closed and reopened later...
|
by: Wittaya |
last post by:
I am using command Me.Closed()in Event of TreeView
AfterSelect.
This below is Error Message appear.
An unhandled exception of type 'System Object Disposed
Exception' occured in...
|
by: bole2cant |
last post by:
The error I get is:
Cannot access a disposed Object named "Form2".
Object name "Form2".
Here is the sequence which gives the error.
Start program. Form1 comes up and has a button to choose...
|
by: Mike |
last post by:
Hello,
Ok I have 2 classes in my project, one is the main form and one is a
connection class, at a certain event on my main form a new instance is
made of the connection class, and a reference...
|
by: aine_canby |
last post by:
Hi,
The problem is that the line -
this.Invoke(new MyDelegate(Function), args); // this = MainForm
is being called after the line -
terminatePopulate = true;
therefore I get an exception...
|
by: rbrowning1958 |
last post by:
Hello,
I am confused by dispose etc. and hope someone can set me right.
1. The Dispose(Bool) the IDE generates for a form has nothing to do
with IDisposable, right?
2. So when is this called?...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |