[RESOLVED] Threads listing and general use
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.
Code:
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
Re: Threads listing and general use
You would probably have to have a list designated for threads, then on application exit -> loop through the list and close all threads.
Re: Threads listing and general use
by default threads are forground and will not be closed if you exit the application you need set IsBackground property of the threads to ture then if you exit the application they all be ceased to exist.
Re: Threads listing and general use
Thanks for answers, I made it keeping the thread in a list.