System.Net.Sockets.TcpClient.Dispose C# (CSharp) Méthode

Dispose() public méthode

public Dispose ( ) : void
Résultat void
        public void Dispose()
        {
            Dispose(true);
        }

Same methods

TcpClient::Dispose ( bool disposing ) : void

Usage Example

        public async Task ReadLineAsync_ThrowsOnConnectionClose()
        {
            TcpListener listener = new TcpListener(IPAddress.Loopback, 0);

            try
            {
                listener.Start();
                Task<TcpClient> acceptTask = listener.AcceptTcpClientAsync();

                TcpClient client = new TcpClient();
                await client.ConnectAsync(IPAddress.Loopback, ((IPEndPoint)listener.LocalEndpoint).Port);

                using (TcpClient serverTcpClient = await acceptTask)
                {
                    TcpClientConnectionChannel channel = new TcpClientConnectionChannel(serverTcpClient);
                    client.Dispose();

                    await Assert.ThrowsAsync<ConnectionUnexpectedlyClosedException>(async () =>
                    {
                        await channel.ReadLineAsync();
                    });
                }
            }
            finally
            {
                listener.Stop();
            }
        }
All Usage Examples Of System.Net.Sockets.TcpClient::Dispose