New to threads

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a test application that will run multiple types of tests. Some are
quite short (milli-seconds to seconds) and can run in parallel and others
need to run serially - they take several minutes to run. I've done some
reading and it doesn't seem that pooling will meet my needs because I can't
define priorities. Does someone have an example of how I can create and
manage various threads by priority levels? For example, I may have (3) test
cases that can run in parallel and therefore are priority 2. I have (2) test
cases that need to run alone and are therefore priority 1. The test cases
could come at me in any order.
 
How about a switch statement where you set the thread priority depending on
what kind of test it is? Something like this:

Thread t = new Thread(...); // create a thread object somehow.
switch(TestType) {
case "parallel":
t.Priority = ThreadPriority.BelowNormal; // or .Lowest if you prefer
case "serial":
t.Priority = ThreadPriority.Normal; // or .AboveNormal if you
prefer.
default:
t.Priority = Normal;
}
t.Start();

Or am I missing the point of your question? This answer seems too easy, so
maybe I'm not getting what you're really asking.
 
Steve Teeples said:
I have a test application that will run multiple types of tests. Some are
quite short (milli-seconds to seconds) and can run in parallel and others
need to run serially - they take several minutes to run. I've done some
reading and it doesn't seem that pooling will meet my needs because I can't
define priorities. Does someone have an example of how I can create and
manage various threads by priority levels? For example, I may have (3) test
cases that can run in parallel and therefore are priority 2. I have (2) test
cases that need to run alone and are therefore priority 1. The test cases
could come at me in any order.

You could use a custom thread pool - I can't remember off-hand whether
my own gives easy access to thread priorities, but you could change it
easily:

http://www.pobox.com/~skeet/csharp/miscutil
 
Back
Top