Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Thread management

Posted on 2011-03-16
3
Medium Priority
?
341 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 800 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 1200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

704 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