rmmarsh
asked on
Need more help on threads...
I have a main process, with one additional thread which works great. I want to be able to do other things while the separate thread is running, but then when the thread completes, I want to resume the next statement after which I started the thread. (hope that makes sense.)... my code follows:
ParameterizedThreadStart pts = new ParameterizedThreadStart(g etISBNPric ingData);
Thread t = new Thread(pts);
ArrayList al = new ArrayList();
al.Add(initialISBNRetValue );
al.Add(isbnRetValue);
t.Start(al);
// need to come back here to next statement when thread is finished processing, but not until
How do I do this?
ParameterizedThreadStart pts = new ParameterizedThreadStart(g
Thread t = new Thread(pts);
ArrayList al = new ArrayList();
al.Add(initialISBNRetValue
al.Add(isbnRetValue);
t.Start(al);
// need to come back here to next statement when thread is finished processing, but not until
How do I do this?
you just need:
t.Join()
t.Join()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I tried thread.join(), but "message pumping" was "suspended", ie I couldn't do anything in the Windows program while the thread was running.
I need to be able to run other tasks in the main form of my Windows program.
Is there a way I can do something like this?
while(signal not received from thread)
sleep();
I need to be able to run other tasks in the main form of my Windows program.
Is there a way I can do something like this?
while(signal not received from thread)
sleep();
ASKER
I also noticed that the join() will "block the calling thread" until the thread terminates... doesn't this mean that my main process (mainForm) will be blocked until the thread terminates? I want to run the thread, and still be able to run other processes (methods) in the windows program.
Hope that makes it clearer...
R
Hope that makes it clearer...
R
Yes, the example I provided above will do this
As an alternative, you can use some kind of synchronization event, by example a ManualResetEvent object.
public ManualResetEvent manualEvent; // put as a class member
// do all the thread stuff
ParameterizedThreadStart pts = new ParameterizedThreadStart(g etISBNPric ingData);
Thread t = new Thread(pts);
ArrayList al = new ArrayList();
al.Add(initialISBNRetValue );
al.Add(isbnRetValue);
manualEvent = new ManualResetEvent(false);
t.Start(al);
manualEvent.WaitOne();
// inside the thread
void getISBNPricingData(ArrayLi st array)
{
// do all your stuff
manualEvent.Set();
}
public ManualResetEvent manualEvent; // put as a class member
// do all the thread stuff
ParameterizedThreadStart pts = new ParameterizedThreadStart(g
Thread t = new Thread(pts);
ArrayList al = new ArrayList();
al.Add(initialISBNRetValue
al.Add(isbnRetValue);
manualEvent = new ManualResetEvent(false);
t.Start(al);
manualEvent.WaitOne();
// inside the thread
void getISBNPricingData(ArrayLi
{
// do all your stuff
manualEvent.Set();
}
ASKER
Thank you all; it works like a champ!
ASKER
Thank you all; it works like a champ!
To do other stuff while the thread is running check to see if the thread is alive, like this
Open in new window