private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // dispose managed state (managed objects). if (_command != null) { _command.Dispose(); _command = null; } else { void f() { _objExcel.Dispose(); _objExcel = null; } f(); } } disposedValue = true; } }