/// <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> /// Enforces that current instance is not "close". /// All access to disposable state should go through this routine. /// </summary> /// <returns></returns> internal BatchClientDisposableStateBox GetStateThrowIfNotOpen() { BatchClientDisposableStateBox localState = _disposableStateBox; if (null != localState) { return(localState); } // TODO: BatchException is not yet ready for this... do we need to create simpler BatchExceptions for stuff like this? throw new InvalidOperationException(BatchErrorMessages.BatchClientIsClosed); }
private BatchClient() { _disposableStateBox = new BatchClientDisposableStateBox(this); // // Add custom behaviors which are by default on every batch client // this.CustomBehaviors.Add(RetryPolicyProvider.ExponentialRetryProvider(TimeSpan.FromSeconds(1), 6)); //Add default AddTaskResultHandler this.CustomBehaviors.Add(new AddTaskCollectionResultHandler(AddTaskCollectionResultHandler.DefaultAddTaskCollectionResultHandler)); }
private BatchClient() { _disposableStateBox = new BatchClientDisposableStateBox(this); // prepopulate the custom behaviors _disposableStateBox.CustomBehaviors = new List <BatchClientBehavior>(); // // Add custom behaviors which are by default on every batch client // //Add default AddTaskResultHandler this.CustomBehaviors.Add(new AddTaskCollectionResultHandler(AddTaskCollectionResultHandler.DefaultAddTaskCollectionResultHandler)); }
/// <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); }