Example #1
0
        public override void Post(SendOrPostCallback callback, object state)
        {
            // There is two cases:
            //
            //   1) We are either in normal MicroThread inside Scheduler.Step() (CurrentThread test),
            //      in which case we will directly execute the callback to avoid further processing from scheduler.
            //      Also, note that Wait() sends us event that are supposed to come back into scheduler.
            //      NOTE: As it will end up on the callstack, it might be better to Schedule it instead (to avoid overflow)?
            //
            //   2) Otherwise, we just received an external task continuation (i.e. Task.Sleep()), or a microthread triggering
            //      another, so schedule it so that it comes back in our regular scheduler.

            if (microThread.Scheduler.RunningMicroThread == microThread)
            {
                callback(state);
            }
            else if (microThread.State == MicroThreadState.Completed)
            {
                throw new InvalidOperationException("MicroThread is already completed but still posting continuations.");
            }
            else
            {
                microThread.ScheduleContinuation(microThread.ScheduleMode, callback, state);
            }
        }
Example #2
0
 public void OnCompleted(Action continuation)
 {
     microThread.ScheduleContinuation(ScheduleMode.Last, continuation);
 }