/// <summary> /// Begins the connect. /// </summary> /// <param name="remoteEp">The remote ep.</param> /// <param name="callback">The callback.</param> /// <param name="state">The state.</param> /// <returns>Async property</returns> public virtual IAsyncResult BeginConnect(AddressEndPoint remoteEp, AsyncCallback callback, object state) { Interlocked.Increment(ref mAsyncActiveConnectCount); ChannelConnectDelegate d = new ChannelConnectDelegate(this.Connect); if (this.mAsyncActiveConnectEvent == null) { lock (this) { if (this.mAsyncActiveConnectEvent == null) { this.mAsyncActiveConnectEvent = new AutoResetEvent(true); } } } this.mAsyncActiveConnectEvent.WaitOne(); this.mConnectDelegate = d; return(d.BeginInvoke(remoteEp, callback, state)); }
/// <summary> /// Ends the connect. /// </summary> /// <param name="asyncResult">The async result.</param> /// <param name="remoteEp">The remote ep.</param> /// <returns>SessionId</returns> public virtual string EndConnect(IAsyncResult asyncResult, AddressEndPoint remoteEp) { if (asyncResult == null) { ThrowHelper.ThrowArgumentNullException("asyncResult"); } if (this.mConnectDelegate == null) { ThrowHelper.ThrowArgumentException("Wrong async result or EndConnect called multiple times.", "asyncResult"); } try { return(this.mConnectDelegate.EndInvoke(asyncResult)); } finally { this.mConnectDelegate = null; this.mAsyncActiveConnectEvent.Set(); CloseAsyncActiveConnectEvent(Interlocked.Decrement(ref mAsyncActiveConnectCount)); } }