In that case, spining up a new thread for each one is probably the way to go
as long as not over 800 or so. I would contain the thread inside an
object - say MyWorker. MyWorker will have things like Start()/Stop()
methods and any properties you want to monitor. Then just store MyWorkers
in an arraylist or something. Then you can easily enum the arraylist to see
what each thread is doing, report status, etc. MyWorker would need to sync
any shared vars as normal as your vars will be updated by the worker thread
and read by some other thread(s) such as monitors, etc.
--
William Stacey, MVP
http://mvp.support.microsoft.com
wdewebserver said:
Thank you both for your prompt response. The tasks are all rather long
running processes and I need a way were they can run in parallel. If I use
just one thread, I end up having a long batch window. As you suggest
using
a
ThreadPool, do you have any examples that I can use? I need to show the
status of the thread as well.
TIA
William Stacey said:
Naturally, thread does != speed. So it very well could be that one thread
for each row will cause the entire job to complete much *slower then
if
just
using one thread or a thread pool. If you do need threads, I would
also
use
the Thread pool like Alvin said unless you have a compelling reason
not
to.
Would need to know more about the requirements.
--
William Stacey, MVP
http://mvp.support.microsoft.com
How can I handle threading in a scenario like the following? The tasks
have
to execute simultaneously. I need a way of identifying which thread is
busy
running and its status and also be able to abort or cause one thread to
sleep.
foreach(DataRow row in TaskTable.Rows)
{
CompData compData = new CompData(row["TASK_ID"].ToString(),
row["TASK_PERC"]);
Thread taskThread = new Thread(new ThreadStart(compData.PerformTask));
taskThread.Name = row["TASK_NAME"].ToString();
taskThread.Start();
}
TIA