Otex
February 7th, 2009, 10:43 PM
I need to add thread to various things in an application I am working on and I have a bit of difficulty with the architecture and control of the threads.
I will have a few questions, all on threads, lets start simple
I have a main form which needs to spawn a second form when we click a button but I need to still be able to use the parent form.
I have something like.
private void button4_Click(object sender, EventArgs e)
{
Thread threadErrorPanel = new Thread(new ThreadStart(ErrorPanelStart));
threadErrorPanel.Start();
}
private void ErrorPanelStart()
{
ErrorPanel fm2 = new ErrorPanel();
fm2.ShowDialog();
}
It works fine, the two problems are:
a. If I click on the button again it lanches a 3rd form etc..
-- How can I check if a thread is already running ?
b. if I close the Main form the 2nd form is still running
-- How can I make main close all the threads that have been started ?
c. How can I list all the threads launched from my application?
Do I have to create a hashtable and populate it with my threads as I start them ? If so how can I maintain the table when a thread abnormally aborts ?
Thanks
I will have a few questions, all on threads, lets start simple
I have a main form which needs to spawn a second form when we click a button but I need to still be able to use the parent form.
I have something like.
private void button4_Click(object sender, EventArgs e)
{
Thread threadErrorPanel = new Thread(new ThreadStart(ErrorPanelStart));
threadErrorPanel.Start();
}
private void ErrorPanelStart()
{
ErrorPanel fm2 = new ErrorPanel();
fm2.ShowDialog();
}
It works fine, the two problems are:
a. If I click on the button again it lanches a 3rd form etc..
-- How can I check if a thread is already running ?
b. if I close the Main form the 2nd form is still running
-- How can I make main close all the threads that have been started ?
c. How can I list all the threads launched from my application?
Do I have to create a hashtable and populate it with my threads as I start them ? If so how can I maintain the table when a thread abnormally aborts ?
Thanks