c# - Is waiting a thread to be alive with a loop good practice? -
do have this?
// loop until worker thread activates. while (!workerthread.isalive);
wouldn't better use manualresetevent (or else) @ start of thread's function?
edit 1:
perhaps in msdn example context "appropiate":
// start worker thread. workerthread.start(); console.writeline("main thread: starting worker thread..."); // loop until worker thread activates. while (!workerthread.isalive);
otherwise feels awful code smell.
source: http://msdn.microsoft.com/en-us/library/7a2f3ay4(v=vs.80).aspx
please ignore msdn example, it's horrible , senseless. in particular, spin waiting on isalive
makes no sense because there no way thread terminated "before has chance execute", msdn says. thread free not check flag set requesting termination until ready. spin-waiting on isalive
never makes sense -- use thread.join()
wait on exit, , events (or monitors) wait other states.
Comments
Post a Comment