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

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -