G
Guest
Hello Everyone,
I just started learning Threading in C#. I read lot of articles and what I
am trying to accomplish here is
that I have an array of string and I want to pass the member of that array
to each thread one by one until the processing is done.
how can I pass the values one by one to myThreadprocess1 and as soon as one
thread is done with the process,
it should grab another item from array and process that item. How can I
accomplish this? Below is my code:
private void processTest()
{
string[] x = { 1234, 6789, 35678, 6789, 023456};
AutoResetEvent MyThread1 = new AutoResetEvent(false);
AutoResetEvent MyThread2 = new AutoResetEvent(false);
ThreadPool.QueueUserWorkItem(new WaitCallback(MyThreadProcess1,
x[0]), MyThread1);
ThreadPool.QueueUserWorkItem(new WaitCallback(MyThreadProcess2,
x[1]), MyThread2);
MyThread1.WaitOne();
MyThread2.WaitOne();
}
static void MyThreadProcess1(Object state)
{
}
I just started learning Threading in C#. I read lot of articles and what I
am trying to accomplish here is
that I have an array of string and I want to pass the member of that array
to each thread one by one until the processing is done.
how can I pass the values one by one to myThreadprocess1 and as soon as one
thread is done with the process,
it should grab another item from array and process that item. How can I
accomplish this? Below is my code:
private void processTest()
{
string[] x = { 1234, 6789, 35678, 6789, 023456};
AutoResetEvent MyThread1 = new AutoResetEvent(false);
AutoResetEvent MyThread2 = new AutoResetEvent(false);
ThreadPool.QueueUserWorkItem(new WaitCallback(MyThreadProcess1,
x[0]), MyThread1);
ThreadPool.QueueUserWorkItem(new WaitCallback(MyThreadProcess2,
x[1]), MyThread2);
MyThread1.WaitOne();
MyThread2.WaitOne();
}
static void MyThreadProcess1(Object state)
{
}