/// <summary>
        ///     When overridden in a derived class, dispatches an asynchronous message to a synchronization context.
        /// </summary>
        /// <param name="d">The <see cref="SendOrPostCallback" /> delegate to call.</param>
        /// <param name="state">The object passed to the delegate.</param>
        public override void Post(SendOrPostCallback d, object state)
        {
            // Queue the item and don't wait for its execution.
            // TODO: This is risky because an unhandled exception will terminate the main thread. Use with caution.
            var item = new SendOrPostCallbackItem(d, state, ExecutionType.Post);

            MessageQueue.PushMessage(item);
        }
        /// <summary>
        ///     When overridden in a derived class, dispatches a synchronous message to a synchronization context.
        /// </summary>
        /// <param name="d">The <see cref="SendOrPostCallback" /> delegate to call.</param>
        /// <param name="state">The object passed to the delegate. </param>
        public override void Send(SendOrPostCallback d, object state)
        {
            var item = new SendOrPostCallbackItem(d, state, ExecutionType.Send);

            MessageQueue.PushMessage(item);

            item.ExecutionCompleteWaitHandle.WaitOne();

            if (item.ExecutedWithException)
            {
                throw item.Exception;
            }
        }
Exemple #3
0
 /// <summary>
 ///     Pushes the specified item onto this instance.
 /// </summary>
 /// <param name="item">The item to enqueue.</param>
 public void PushMessage(SendOrPostCallbackItem item)
 {
     _queue.Enqueue(item);
     _semaphore.Release();
 }
 /// <summary>
 ///     Pushes the specified item onto this instance.
 /// </summary>
 /// <param name="item">The item to enqueue.</param>
 public void PushMessage(SendOrPostCallbackItem item)
 {
     _queue.Enqueue(item);
 }