|
-
February 7th, 2009, 11:43 PM
#1
[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
-
February 8th, 2009, 05:29 PM
#2
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.
-
February 9th, 2009, 12:40 PM
#3
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.
Please rate my post if it was helpful for you.  Java, C#, C++, PHP, ASP.NET
SQL Server, MySQL
DirectX
MATH Touraj Ebrahimi
[toraj_e] [at] [yahoo] [dot] [com]
-
February 15th, 2009, 02:00 AM
#4
Re: Threads listing and general use
Thanks for answers, I made it keeping the thread in a list.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|