public void PostAsync(Action msg) { _msgQueue.Enqueue(msg); Action tmp; while (!_msgQueue.TryPeek(out tmp)) { if (_msgQueue.Count == 0) { return; // The message was processed immediately, and we can just return. } } if (msg == tmp) { Scheduler.AddActor(this); // The message was sent while the actor was idle; restart it to continue processing. } }