Threading problem

I have a bunch of threads that perform some of the longer operations in my program.  I am using the form:

ThreadStart starter = new ThreadStart(func);
Thread t = new Thread(starter);

1.  Should I change it all to delegates, does it matter?

2.  When I close my main application window, threads still run to completion, I want to kill them all.
3.  When a user logs off but the program is still running, I want to kill all open threads (or at least notify the UI to wait until they have completed).

What is the best way to structure this?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

if you want to stop the working when your main window has been closed, you can call Abort() on each runing thread in your main windows close event handler.

to have a thread waiting for another thread to terminate, use Join() on the first thread.
jjacksnAuthor Commented:
so I just have a list of threads Thread[] and call t.WhatyouSaid from my main, calling thread?  

when the thread completes, will calling t.Join() or t.Abort() throw an error, or just do nothing?
jjacksnAuthor Commented:
Should I be using thread pools for this?  If so, how do I do that (can you point me to a tutorial).
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

This article describes how to run a worker thread, send information from it to main thread and stop worker thread correctly.

About thread pool - thread pool is used when all threads make the same work which may be done by same thread function. For example, threads talking with clients in HTTP server. If this is your case, and number of clients is not restricted, consider using thread pool.
If all your threads are different, each one of them make it's own work, use the way described in the article for each thread.
jjacksnAuthor Commented:
They are pretty simple threads, I'm just using them for calls to remote objects that take a while.

ThreadStart starter = new ThreadStart(func);
Thread t = new Thread(starter);
t.isBackground = true;

By setting the thread to a background thread means that when the main thread is killed, all other threads die immediately

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.