Skip to content

Commit e175027

Browse files
authored
Add using to NetworkStream/WriteTimeout examples
Add using to NetworkStream/WriteTimeout examples
2 parents 22c1d28 + 133dc47 commit e175027

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

snippets/cpp/VS_Snippets_Remoting/NclTcpServerSync/cpp/tcplistener.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@ int main()
3131
// Stop listening for incoming connections
3232
// and close the server.
3333
tcpListener->Stop();
34+
35+
// Dispose allocated resources.
36+
delete networkStream;
37+
delete tcpClient;
3438
}
3539
//</snippet0>

snippets/csharp/System.Net.Sockets/NetworkStream/WriteTimeout/tcplistener.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public static void Main()
1717
Console.WriteLine("Waiting for a connection....");
1818

1919
// Accept the pending client connection.
20-
TcpClient tcpClient = tcpListener.AcceptTcpClient();
20+
using TcpClient tcpClient = tcpListener.AcceptTcpClient();
2121
Console.WriteLine("Connection accepted.");
2222
// Get the stream to write the message
2323
// that will be sent to the client.
24-
NetworkStream networkStream = tcpClient.GetStream();
24+
using NetworkStream networkStream = tcpClient.GetStream();
2525
string responseString = "Hello.";
2626
// Set the write timeout to 10 millseconds.
2727
networkStream.WriteTimeout = 10;

0 commit comments

Comments
 (0)