Solved

Threading problem

Posted on 2003-11-13
7
290 Views
Last Modified: 2010-04-16
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);
t.Start();

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?
0
Comment
Question by:jjacksn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 11

Expert Comment

by:Agarici
ID: 9741587
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.
0
 
LVL 5

Author Comment

by:jjacksn
ID: 9741858
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?
0
 
LVL 5

Author Comment

by:jjacksn
ID: 9741893
Should I be using thread pools for this?  If so, how do I do that (can you point me to a tutorial).
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 48

Expert Comment

by:AlexFM
ID: 9742042
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9742081
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.
0
 
LVL 5

Author Comment

by:jjacksn
ID: 9744924
They are pretty simple threads, I'm just using them for calls to remote objects that take a while.
0
 
LVL 22

Accepted Solution

by:
_TAD_ earned 250 total points
ID: 9745466


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


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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question