/// <summary> /// Begins the create proxy. /// </summary> /// <param name="callback">The callback.</param> /// <param name="state">The state.</param> /// <returns>Async property</returns> public IAsyncResult BeginCreateProxy(AsyncCallback callback, object state) { //szálbiztos nővelés, megmutatja hány várakozó szál van, az increment pedig nőveli ezen változó értékét Interlocked.Increment(ref mAsyncActiveCreateProxyCount); CreateProxyDelegate <TContract> d = new CreateProxyDelegate <TContract>(this.CreateProxy); if (this.mAsyncActiveCreateProxyEvent == null) { lock (this) { if (this.mAsyncActiveCreateProxyEvent == null) { this.mAsyncActiveCreateProxyEvent = new AutoResetEvent(true); } } } //event várakoztatása this.mAsyncActiveCreateProxyEvent.WaitOne(); this.mCreateProxyDelegate = d; return(d.BeginInvoke(callback, state)); }
/// <summary> /// Ends the create proxy. /// </summary> /// <param name="asyncResult">The async result.</param> /// <returns>Contract</returns> public TContract EndCreateProxy(IAsyncResult asyncResult) { if (asyncResult == null) { ThrowHelper.ThrowArgumentNullException("asyncResult"); } if (this.mCreateProxyDelegate == null) { ThrowHelper.ThrowArgumentException("Wrong async result or EndCreateProxy called multiple times.", "asyncResult"); } try { return(this.mCreateProxyDelegate.EndInvoke(asyncResult)); } finally { this.mCreateProxyDelegate = null; this.mAsyncActiveCreateProxyEvent.Set(); CloseAsyncActiveCreateProxyEvent(Interlocked.Decrement(ref mAsyncActiveCreateProxyCount)); } }