예제 #1
0
 // Internal helper to call the right form of the OnClose() method
 // asynchronously.  It depends on whether the type can support the
 // async API's and how the current Communication object is being closed.
 private async Task OnCloseAsyncInternal(TimeSpan timeout)
 {
     // If this type is capable of overriding OnCloseAsync,
     // then use it for both async and sync closes
     if (SupportsAsyncOpenClose)
     {
         // The class supports OnCloseAsync(), so use it
         await OnCloseAsync(timeout);
     }
     else
     {
         // This type is an external type that cannot override OnCloseAsync.
         // If this is a synchronous close, invoke the synchronous OnClose)
         if (_isSynchronousClose)
         {
             await TaskHelpers.CallActionAsync(OnClose, timeout);
         }
         else
         {
             // The class does not support OnCloseAsync, and this is an asynchronous
             // close, so use the Begin/End pattern
             await Task.Factory.FromAsync(OnBeginClose, OnEndClose, timeout, TaskCreationOptions.RunContinuationsAsynchronously);
         }
     }
 }
예제 #2
0
 // Internal helper to call the right form of the OnOpen() method
 // asynchronously.  It depends on whether the type can support the
 // async API's and how the current Communication object is being opened.
 private async Task OnOpenAsyncInternal(TimeSpan timeout)
 {
     // If this type is capable of overriding OnOpenAsync,
     // then use it for both async and sync opens
     if (SupportsAsyncOpenClose)
     {
         Console.WriteLine("CommunicationObject.OnOpenAsyncInternal.SupportsAsyncOpenClose");
         // The class supports OnOpenAsync(), so use it
         await OnOpenAsync(timeout);
     }
     else
     {
         // This type is an external type that cannot override OnOpenAsync.
         // If this is a synchronous open, invoke the synchronous OnOpen)
         if (_isSynchronousOpen)
         {
             Console.WriteLine("CommunicationObject.OnOpenAsyncInternal._isSynchronousOpen");
             await TaskHelpers.CallActionAsync <TimeSpan>(OnOpen, timeout);
         }
         else
         {
             // The class does not support OnOpenAsync, so use the Begin/End pattern
             Console.WriteLine("CommunicationObject.OnOpenAsyncInternal.!_isSynchronousOpen");
             await Task.Factory.FromAsync(OnBeginOpen, OnEndOpen, timeout, TaskCreationOptions.RunContinuationsAsynchronously);
         }
     }
 }
예제 #3
0
 // Helper used to close another CommunicationObject "owned" by the current one.
 // It is used to propagate the use of either the synchronous or asynchronous methods
 internal async Task CloseOtherAsync(ICommunicationObject other, TimeSpan timeout)
 {
     // If the current object is being closed synchronously, use the synchronous
     // close path for the other object.
     if (_isSynchronousClose)
     {
         await TaskHelpers.CallActionAsync(other.Close, timeout);
     }
     else
     {
         await Task.Factory.FromAsync(other.BeginClose(timeout, callback: null, state: null), other.EndClose);
     }
 }
예제 #4
0
 // Helper used to open another CommunicationObject "owned" by the current one.
 // It is used to propagate the use of either the synchronous or asynchronous methods
 internal async Task OpenOtherAsync(ICommunicationObject other, TimeSpan timeout)
 {
     // If the current object is being opened synchronously, use the synchronous
     // open path for the other object.
     if (_isSynchronousOpen)
     {
         await TaskHelpers.CallActionAsync(other.Open, timeout);
     }
     else
     {
         await Task.Factory.FromAsync(other.BeginOpen(timeout, callback: null, state: null), other.EndOpen);
     }
 }
예제 #5
0
 // Helper used to close another CommunicationObject "owned" by the current one.
 // It is used to propagate the use of either the synchronous or asynchronous methods
 internal Task CloseOtherAsync(ICommunicationObject other, TimeSpan timeout)
 {
     // If the current object is being closed synchronously, use the synchronous
     // close path for the other object.
     if (_isSynchronousClose)
     {
         return(TaskHelpers.CallActionAsync(other.Close, timeout));
     }
     else
     {
         return(Task.Factory.FromAsync(other.BeginClose, other.EndClose, timeout, null));
     }
 }
예제 #6
0
 // Helper used to open another CommunicationObject "owned" by the current one.
 // It is used to propagate the use of either the synchronous or asynchronous methods
 internal Task OpenOtherAsync(ICommunicationObject other, TimeSpan timeout)
 {
     // If the current object is being opened synchronously, use the synchronous
     // open path for the other object.
     if (_isSynchronousOpen)
     {
         return(TaskHelpers.CallActionAsync(other.Open, timeout));
     }
     else
     {
         return(Task.Factory.FromAsync(other.BeginOpen, other.EndOpen, timeout, null));
     }
 }
예제 #7
0
            private new async Task OnCloseAsyncInternal(TimeSpan timeout)
            {
                TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

                if (_isSynchronousClose)
                {
                    await TaskHelpers.CallActionAsync(base.OnClose, timeoutHelper.RemainingTime());
                }
                else
                {
                    await Task.Factory.FromAsync(base.OnBeginClose, base.OnEndClose, timeoutHelper.RemainingTime(), TaskCreationOptions.None);
                }

                await CloseOtherAsync(_innerChannelFactory, timeoutHelper.RemainingTime());
            }