Example #1
0
            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;
            }
Example #2
0
        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;
                }
            }
        }