Solved

Thread management

Posted on 2011-03-16
3
339 Views
Last Modified: 2012-05-11
I want to create a multi threaded feature that will create up to "N" threads.  Once each thread is created I need to be able to track each thread's progress (start, processing, complete).  If all threads are currently used I need to know that so the "N" thread limit is followed.  How is this best achieved?
0
Comment
Question by:Phil5780
[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
3 Comments
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 35145158
Check out this free e-book. It's the bible for C# threading.

http://www.albahari.com/threading/

Hope that helps.
0
 
LVL 11

Assisted Solution

by:Sudhakar Pulivarthi
Sudhakar Pulivarthi earned 200 total points
ID: 35147635
Hi,
This can be achived using .NET ThreadPool which has controlled mechanism of creation and deletion of threads as used in the application.
Set SetMaxThreads to N threads max-limit which you want  and SetMinThreads to have minimum threads always alive.

Check out the tutorial to use thread pool and mould to your requirement.
http://msdn.microsoft.com/en-us/library/0ka9477y(v=VS.85).aspx
0
 
LVL 10

Accepted Solution

by:
Nash2334 earned 300 total points
ID: 35148364
Any time you are working with multi-threaded applications the easiest way to do so will be to use the .NET BackgroundWorker.  The BackgroundWorker reports progress, supports cancellation, and has a RunWorkerCompleted event that is raised when it's done doing whatever you ask it to do.

To track the progress of N number of threads, you can simply create a List<BackgroundWorker> of background workers, then cycle through the list and check if the workers in the list are busy.

Following is one my responses regarding BWs from a previous thread:

-------------------

BackgroundWorker is the way to go.  The BW has built in management capabilities, progress reporting, exception handling and cancellation methods that make creating multi-threaded applications quite easy.   The two primary events you will want to concern yourself with are DoWork (code the background thread executes) and RunWorkerCompleted (code to execute when the thread completes).  The BW also has built in exception handling; you can check to see if any exception is thrown when the BW completes.  The RunWorkerAsync() method kicks it off.

BackgroundWorker bw = new BackgroundWorker();
bw.WorkerSupportsCancellation = true;
bw.WorkerReportsProgress = true;
bw.ProgressChanged += new ProgressChangedEventHandler(_bw_ProgressChanged);
bw.DoWork += new DoWorkEventHandler(_bw_DoWork);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_bw_RunWorkerCompleted);
bw.RunWorkerAsync();
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
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…

627 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