Skip to content

Commit 1b3546c

Browse files
committed
Change: Add using and delete statements to examples
1 parent ed32a71 commit 1b3546c

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,10 @@ 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;
38+
delete tcpListener;
3439
}
3540
//</snippet0>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ public static void Main()
1212
{
1313
// Create the server side connection and
1414
// start listening for clients.
15-
TcpListener tcpListener = new TcpListener(IPAddress.Any,11000);
15+
using TcpListener tcpListener = new TcpListener(IPAddress.Any,11000);
1616
tcpListener.Start();
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)