MsgPack.Rpc.Client.RpcClient.ShutdownAsync C# (CSharp) Method

ShutdownAsync() public method

Initiates shutdown of current connection.
public ShutdownAsync ( ) : Task
return Task
		public Task ShutdownAsync()
		{
			this.VerifyIsNotDisposed();

			if ( this._transportShutdownCompletionSource != null )
			{
				return null;
			}

			var taskCompletionSource = new TaskCompletionSource<object>();
			if ( Interlocked.CompareExchange( ref this._transportShutdownCompletionSource, taskCompletionSource, null ) != null )
			{
				return null;
			}

			this._transport.ShutdownCompleted += this.OnTranportShutdownComplete;
			this._transport.BeginShutdown();
			return taskCompletionSource.Task;
		}

Usage Example

Example #1
0
 public void TestShutdownAsync_TransportShutdownIsInitiated()
 {
     using (var environment = new InProcTestEnvironment())
         using (var target = new RpcClient(_loopbackEndPoint, environment.Configuration, null))
         {
             int isShutdownCompleted = 0;
             target.EnsureConnected();
             target.Transport.ShutdownCompleted += (sender, e) => Interlocked.Exchange(ref isShutdownCompleted, 1);
             using (var task = target.ShutdownAsync())
             {
                 Assert.That(target.Transport.IsClientShutdown);
                 Assert.That(task.Wait(TimeSpan.FromSeconds(1)));
                 Assert.That(isShutdownCompleted, Is.EqualTo(1));
             }
         }
 }
All Usage Examples Of MsgPack.Rpc.Client.RpcClient::ShutdownAsync