In the following example, could HasStarted() ever return false (meaning
that ThreadJob() would get called *after* Foo() returns)?
Basically I don't ever want Foo() to return until after the thread has
executed.
------
void Foo() {
Thread thread = new Thread(ThreadJob);
thread.Start();
if (HasStarted(thread)) {
thread.Join();
}
}
void HasStarted(Thread t) {
return
t.ThreadState & (ThreadState.Stopped | ThreadState.Unstarted)) == 0;
}
------
I ask because I don't know for sure what exactly happens when
Thread.Start() is called.