TcpClient.IDisposable.Dispose 方法

定義

釋放 TcpClient 所使用的所有資源。Releases all resources used by the TcpClient.

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

 virtual void System.IDisposable.Dispose() = IDisposable::Dispose;
void IDisposable.Dispose ();
abstract member System.IDisposable.Dispose : unit -> unit
override this.System.IDisposable.Dispose : unit -> unit
Sub Dispose () Implements IDisposable.Dispose

實作

備註

當您完成使用 TcpClient時,請呼叫 IDisposable。Call IDisposable.Dispose when you are finished using the TcpClient. IDisposable 方法會使 TcpClient 處於無法使用的狀態。The IDisposable.Dispose method leaves the TcpClient in an unusable state. 呼叫 IDisposable 之後,您必須釋放所有對 TcpClient 的參考,讓垃圾收集行程可以回收 TcpClient 佔用的記憶體。After calling IDisposable.Dispose, you must release all references to the TcpClient so the garbage collector can reclaim the memory that the TcpClient was occupying. 如需詳細資訊,請參閱清除非受控資源執行 Dispose 方法For more information, see Cleaning Up Unmanaged Resources and Implementing a Dispose Method.

注意

在您釋放 TcpClient的最後一個參考之前,請一律呼叫 IDisposable。Always call IDisposable.Dispose before you release your last reference to the TcpClient. 否則,在垃圾收集行程呼叫 TcpClient 物件的Finalize方法之前,將不會釋放它正在使用的資源。Otherwise, the resources it is using will not be freed until the garbage collector calls the TcpClient object's Finalize method.

適用於