/// <summary> /// Releases unmanaged resources used by the <see cref="BatchClient"/>, and optionally disposes of managed resources. /// </summary> /// <param name="disposing">Indicates whether the object is being disposed or finalized. If true, the object is /// being disposed and can dispose managed resource. If false, the object is being finalized and should only /// release unmanaged resources.</param> protected virtual void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { // IDisposable only section lock (this._closeLocker) { if (this._disposableStateBox != null) { IProtocolLayer localProto = this.ProtocolLayer; localProto.Dispose(); this._disposableStateBox = null; // null state box signals that the instance is closed } } } _disposed = true; }
/// <summary> /// Starts an asynchronous operation to close the current instance of <see cref="Microsoft.Azure.Batch.BatchClient"/>. /// Closed instances of <see cref="Microsoft.Azure.Batch.BatchClient"/> are unable to make calls to the Batch Service and the behavior and values of any other methods or properties are undefined. /// These restrictions also apply immediately to any objects that can trace instantation back to this <see cref="Microsoft.Azure.Batch.BatchClient"/>. /// This method is threadsafe and can be called any number of times. /// </summary> /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns> public System.Threading.Tasks.Task CloseAsync() { lock (this._closeLocker) { if (this._disposableStateBox != null) { IProtocolLayer localProto = this.ProtocolLayer; localProto.Dispose(); this._disposableStateBox = null; // null state box signals that the instance is closed } } return(Utils.Async.CompletedTask); }