public OpenAsyncResult( ICommunicationObject communicationObject, bool sharedInnerListener, TimeSpan timeout, AsyncCallback callback, object state ) : base(callback, state) { _communicationObject = communicationObject; if (_communicationObject == null || sharedInnerListener) { Complete(true); return; } IAsyncResult result = _communicationObject.BeginOpen( timeout, _onOpenComplete, this ); if (result.CompletedSynchronously) { _communicationObject.EndOpen(result); Complete(true); } }
// 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); } }
/// <summary> /// Abre o objeto de comunicação. /// </summary> /// <param name="communicationObject"></param> /// <returns></returns> private bool OpenCommunicationObject(ICommunicationObject communicationObject) { if (communicationObject == null) { return(false); } try { communicationObject.BeginOpen(new AsyncCallback(OpenCommunicationObjectCallback), communicationObject); return(true); } catch (Exception exception) { AbortCommunication(communicationObject, exception); return(false); } }
protected virtual IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state) { return(inner.BeginOpen(timeout, callback, state)); }
// 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<TimeSpan>(other.Open, timeout); } else { await Task.Factory.FromAsync(other.BeginOpen(timeout, callback: null, state: null), other.EndOpen); } }
public System.IAsyncResult BeginOpen(System.TimeSpan timeout, System.AsyncCallback callback, object state) { return(_communicationObject.BeginOpen(timeout, callback, state)); }
/// <summary> /// Asynchronously opens the connection of the proxy. /// </summary> /// <exception cref="ArgumentNullException">The <paramref name="communicationObject"/> is null.</exception> public static Task OpenAsync(this ICommunicationObject communicationObject) { _ = communicationObject ?? throw new ArgumentNullException(nameof(communicationObject)); return(Task.Factory.FromAsync(communicationObject.BeginOpen(null, null), communicationObject.EndOpen)); }