events between threads?

  • Thread starter Thread starter Terry
  • Start date Start date
T

Terry

Can the main thread be notified of an event raised by a spawned?
A button on a form creates a new thread which will raise an event when
it is finished. When the form is notified of the thread termination
event, I want my form to create a new form and make the new form's MDI
parent the same as it's MDI parent. Problem is that I get an error
stating that controls created in a thread cannot have their parent set
to a form in another thread. If I don't set the MDI parent of the new
form, it flashes up and then dies as the spawned thread dies.
How can I create the new form when the spawned thread dies, set its
mdi parent, and have it persist after the thread dies? (I don't want
to have code on the main form continuously polling the new thread)

thanks!
 
Terry said:
Can the main thread be notified of an event raised by a spawned?
A button on a form creates a new thread which will raise an event when
it is finished. When the form is notified of the thread termination
event, I want my form to create a new form and make the new form's MDI
parent the same as it's MDI parent. Problem is that I get an error
stating that controls created in a thread cannot have their parent set
to a form in another thread. If I don't set the MDI parent of the new
form, it flashes up and then dies as the spawned thread dies.
How can I create the new form when the spawned thread dies, set its
mdi parent, and have it persist after the thread dies? (I don't want
to have code on the main form continuously polling the new thread)

Hi Terry,

You could probably call the Invoke method of your form when the thread is
ready to exit. It sounds like you were having problems because you tried to
call the UI thread with your secondary thread. Here are a few articles with
examples that should help:

http://www.windowsforms.net/Default.aspx?tabindex=3&tabid=40#Threading

Joe
 
Back
Top