TcpClient.Dispose 方法

定義

多載

Dispose()

釋放 TcpClient 使用的受控與非受控資源。Releases the managed and unmanaged resources used by the TcpClient.

Dispose(Boolean)

釋放 TcpClient 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the TcpClient and optionally releases the managed resources.

Dispose()

釋放 TcpClient 使用的受控與非受控資源。Releases the managed and unmanaged resources used by the TcpClient.

public:
 virtual void Dispose();
public void Dispose ();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()

實作

Dispose(Boolean)

釋放 TcpClient 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the TcpClient and optionally releases the managed resources.

protected:
 virtual void Dispose(bool disposing);
protected virtual void Dispose (bool disposing);
abstract member Dispose : bool -> unit
override this.Dispose : bool -> unit
Protected Overridable Sub Dispose (disposing As Boolean)

參數

disposing
Boolean

設定為 true 表示釋放 Managed 和 Unmanaged 資源,設定為 false 表示只釋放 Unmanaged 資源。Set to true to release both managed and unmanaged resources; false to release only unmanaged resources.

備註

這個方法是由公用Dispose()方法Finalize和方法所呼叫。This method is called by the public Dispose() method and the Finalize method. Dispose()叫用這個方法, disposing並將參數true設定為。Dispose() invokes this method with the disposing parameter set to true. Finalize叫用這個方法disposing ,並false將設為。Finalize invokes this method with disposing set to false.

disposing 參數為 true 時,這個方法會釋放 TcpClient 參考的任何 Managed 物件所掌握的資源。When the disposing parameter is true, this method releases all resources held by any managed objects that this TcpClient references. 它會叫用每個Dispose()參考物件的方法來執行這項工作。It does this by invoking the Dispose() method of each referenced object.

注意

在應用程式中啟用網路追蹤時,這個成員會輸出追蹤資訊。This member outputs trace information when you enable network tracing in your application. 如需詳細資訊,請參閱.NET Framework 中的網路追蹤For more information, see Network Tracing in the .NET Framework.

給繼承者的注意事項

Dispose 可以被其他物件呼叫多次。 Dispose can be called multiple times by other objects. 覆寫 Dispose(Boolean) 時,請小心不要參考到先前已在對 Dispose 的早期呼叫中被處置 (Dispose) 的物件。When overriding Dispose(Boolean), be careful not to reference objects that have been previously disposed of in an earlier call to Dispose. 如需如何執行Dispose(Boolean)的詳細資訊, 請參閱[執行 Dispose 方法](~/docs/standard/garbage-collection/implementing-dispose.md)。For more information about how to implement Dispose(Boolean), see [Implementing a Dispose Method](~/docs/standard/garbage-collection/implementing-dispose.md). 如需DisposeFinalize()的詳細資訊,請參閱[清除非受控資源](~/docs/standard/garbage-collection/unmanaged.md)和覆[寫 Finalize 方法](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/ddae83kx(v=vs.100))。For more information about Dispose and Finalize(), see [Cleaning Up Unmanaged Resources](~/docs/standard/garbage-collection/unmanaged.md) and [Overriding the Finalize Method](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/ddae83kx(v=vs.100)).

適用於