Guest User

C# TcpClient methods

a guest
Jan 7th, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. public void Close()
  2.         {
  3.             if (Logging.On)
  4.             {
  5.                 Logging.Enter(Logging.Sockets, this, "Close", "");
  6.             }
  7.             ((IDisposable)this).Dispose();
  8.             if (Logging.On)
  9.             {
  10.                 Logging.Exit(Logging.Sockets, this, "Close", "");
  11.             }
  12.         }
  13.  
  14. void IDisposable.Dispose()
  15.         {
  16.             this.Dispose(true);
  17.         }
  18.  
  19. protected virtual void Dispose(bool disposing)
  20.         {
  21.             if (Logging.On)
  22.             {
  23.                 Logging.Enter(Logging.Sockets, this, "Dispose", "");
  24.             }
  25.             if (this.m_CleanedUp)
  26.             {
  27.                 if (Logging.On)
  28.                 {
  29.                     Logging.Exit(Logging.Sockets, this, "Dispose", "");
  30.                 }
  31.                 return;
  32.             }
  33.             if (disposing)
  34.             {
  35.                 IDisposable dataStream = this.m_DataStream;
  36.                 if (dataStream != null)
  37.                 {
  38.                     dataStream.Dispose();
  39.                 }
  40.                 else
  41.                 {
  42.                     Socket client = this.Client;
  43.                     if (client != null)
  44.                     {
  45.                         try
  46.                         {
  47.                             client.InternalShutdown(SocketShutdown.Both);
  48.                         }
  49.                         finally
  50.                         {
  51.                             client.Close();
  52.                             this.Client = null;
  53.                         }
  54.                     }
  55.                 }
  56.                 GC.SuppressFinalize(this);
  57.             }
  58.             this.m_CleanedUp = true;
  59.             if (Logging.On)
  60.             {
  61.                 Logging.Exit(Logging.Sockets, this, "Dispose", "");
  62.             }
  63.         }
Advertisement
Add Comment
Please, Sign In to add comment