public SynchronousWorkItem(SendOrPostCallback sendOrPostCallback, object state, AutoResetEvent ResetEvent, ref WorkItemExecutionInfo WorkItemExecutionInfo) : base(sendOrPostCallback, state) { if (WorkItemExecutionInfo is null) { throw new NullReferenceException(nameof(WorkItemExecutionInfo)); } _SyncObject = ResetEvent; _WorkItemExecutionInfo = WorkItemExecutionInfo; }
public override void Send(SendOrPostCallback post, object state) { if (Thread.CurrentThread == _Thread) { post(state); } else { using var reset_event = new AutoResetEvent(false); var wi_execution_info = new WorkItemExecutionInfo(); _WorkItems.Enqueue(new SynchronousWorkItem(post, state, reset_event, ref wi_execution_info)); _WorkerResetEvent.Set(); reset_event.WaitOne(); if (wi_execution_info.HasException) { throw wi_execution_info.Exception; } } }