private void PostOrSend(SendOrPostCallback d, object state, bool wait) { var id = (ulong)Interlocked.Increment(ref _idFactory); var isCurrentThread = _eventLoop.IsOnEventLoopThread; using (var e = new SynchronizationEventData(_eventLoop, id, d, state, wait && !isCurrentThread)) { SynchronizationEventData tmp = e; _eventLoop.OnEventPublishing(id, ref tmp); if (wait && isCurrentThread) { _eventLoop.OnEventPublished(id, tmp); _eventLoop.OnEventExecuting(id, ref tmp); d(state); _eventLoop.OnEventExecuted(id, tmp, EventStatus.Continue); } else { _events.Enqueue(e); _eventLoop.Publish(id, this, e); e.WaitHandle?.Wait(); } } }
public void Invoke() { SynchronizationEventData tmp = this; EventLoop.OnEventExecuting(Id, ref tmp); Callback?.Invoke(State); EventLoop.OnEventExecuted(Id, tmp, EventStatus.Continue); WaitHandle?.Set(); }