public bool Work() { while (true) { // process nested work jobs first if (subWorker != null) { if (subWorker.Work()) { subWorker = null; } else { // subWorker requested pause return false; } } if (workerInstance == null) { workerInstance = workerMethod(); Start(); } bool done = !workerInstance.MoveNext(); // we're done when we can't get next Enumerator element if (done) { // we truly are done Stop(); workerInstance = null; return true; } else { subWorker = workerInstance.Current as WorkerCoroutine; if (subWorker == null) { // returned null take a break return false; } // returned a subWorker, no time to rest continue; } } }
public bool Work() { TimeHint = 0; while (true) { // process nested work jobs first if (subWorker != null) { if (subWorker.Work()) { subWorker = null; } else { // subWorker requested pause TimeHint = subWorker.TimeHint; if (lastWorker == subWorker) { lastWorkerCount++; } else { lastWorkerCount = 1; } lastWorker = subWorker; return(false); } } if (workerInstance == null) { workerInstance = workerMethod(); Start(); } bool done; try { done = !workerInstance.MoveNext(); // we're done when we can't get next Enumerator element } catch (Exception e) { throw new Exception("Exception in WorkerCoroutine: " + this, e); } if (done) { // we truly are done Stop(); workerInstance = null; return(true); } else { subWorker = workerInstance.Current as WorkerCoroutine; if (subWorker == null) { if (lastWorker == this) { lastWorkerCount++; } else { lastWorkerCount = 1; } lastWorker = this; // returned null take a break if (workerInstance.Current is int) { TimeHint = (int)workerInstance.Current; } return(false); } // returned a subWorker, no time to rest continue; } } }
public void Cancel() { Stop(); workerInstance = null; subWorker = null; }
public bool Work() { TimeHint = 0; while (true) { // process nested work jobs first if (subWorker != null) { if (subWorker.Work()) { subWorker = null; } else { // subWorker requested pause TimeHint = subWorker.TimeHint; if (lastWorker == subWorker) { lastWorkerCount++; } else { lastWorkerCount = 1; } lastWorker = subWorker; return false; } } if (workerInstance == null) { workerInstance = workerMethod(); Start(); } bool done; try { done = !workerInstance.MoveNext(); // we're done when we can't get next Enumerator element } catch(Exception e) { throw new Exception("Exception in WorkerCoroutine: "+this, e); } if (done) { // we truly are done Stop(); workerInstance = null; return true; } else { subWorker = workerInstance.Current as WorkerCoroutine; if (subWorker == null) { if (lastWorker == this) { lastWorkerCount++; } else { lastWorkerCount = 1; } lastWorker = this; // returned null take a break if (workerInstance.Current is int) { TimeHint = (int)workerInstance.Current; } return false; } // returned a subWorker, no time to rest continue; } } }