2017-10-12 2 views
-1

私はこのような子クラスを持っている:子クラスにDisposeメソッドを構築する方法は?

​​

iはSyncTelemetryChannel Disposeメソッドに何を置くべき?現在、私は、この持っている:

public void Dispose() {} 

おかげで、ピーター

+0

'ITelemetryChannel'はインターフェースがありますか? (ダブルチェック) –

+0

disposeパターンを正しく実装する必要があります。あなたのオブジェクトはアンマネージドリソースの所有権を握っていますか? –

答えて

0
public class SyncTelemetryChannel : ITelemetryChannel 
{ 
     private bool _disposed = false; 

     /// <summary> 
     /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. 
     /// </summary> 
     public void Dispose() 
     { 
      Dispose(true); 
      GC.SuppressFinalize(this); 
     } 

     /// <summary> 
     /// Releases unmanaged and - optionally - managed resources. 
     /// </summary> 
     /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> 
     protected virtual void Dispose(bool disposing) 
     { 
      if (_disposed) 
       return; 

      if (disposing) 
      {      
       // Free any other managed objects here.      
      } 

      // Free any unmanaged objects here. 
      _disposed = true; 
     } 

} 
+0

Thanks LP13とEric。私は思っていた、あなたのコメントは私を助けた。 – user1224643

関連する問題