CloudJob.AddTaskAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
AddTaskAsync(CloudTask, ConcurrentDictionary<Type,IFileStagingArtifact>, IEnumerable<BatchClientBehavior>, CancellationToken)
- Source:
- CloudJob.cs
Adds a single task to this CloudJob. To add multiple tasks, use JobOperations.AddTaskAsync.
public System.Threading.Tasks.Task AddTaskAsync (Microsoft.Azure.Batch.CloudTask taskToAdd, System.Collections.Concurrent.ConcurrentDictionary<Type,Microsoft.Azure.Batch.IFileStagingArtifact> allFileStagingArtifacts = default, System.Collections.Generic.IEnumerable<Microsoft.Azure.Batch.BatchClientBehavior> additionalBehaviors = default, System.Threading.CancellationToken cancellationToken = default);
member this.AddTaskAsync : Microsoft.Azure.Batch.CloudTask * System.Collections.Concurrent.ConcurrentDictionary<Type, Microsoft.Azure.Batch.IFileStagingArtifact> * seq<Microsoft.Azure.Batch.BatchClientBehavior> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function AddTaskAsync (taskToAdd As CloudTask, Optional allFileStagingArtifacts As ConcurrentDictionary(Of Type, IFileStagingArtifact) = Nothing, Optional additionalBehaviors As IEnumerable(Of BatchClientBehavior) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- allFileStagingArtifacts
- ConcurrentDictionary<Type,IFileStagingArtifact>
An optional collection to customize and receive information about the file staging process (see FilesToStage). For more information see IFileStagingArtifact.
- additionalBehaviors
- IEnumerable<BatchClientBehavior>
A collection of BatchClientBehavior instances that are applied to the Batch service request after the CustomBehaviors.
- cancellationToken
- CancellationToken
A CancellationToken for controlling the lifetime of the asynchronous operation.
Returns
A Task that represents the asynchronous operation.
Remarks
Each call to this method incurs a request to the Batch service. Therefore, using this method to add multiple tasks is less efficient than using a bulk add method, and can incur HTTP connection restrictions. If you are performing many of these operations in parallel and are seeing client side timeouts (a TaskCanceledException), please see http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit%28v=vs.110%29.aspx or use AddTaskAsync(String, IEnumerable<CloudTask>, BatchClientParallelOptions, ConcurrentBag<ConcurrentDictionary<Type,IFileStagingArtifact>>, Nullable<TimeSpan>, IEnumerable<BatchClientBehavior>).
The add task operation runs asynchronously.
Applies to
AddTaskAsync(IEnumerable<CloudTask>, BatchClientParallelOptions, ConcurrentBag<ConcurrentDictionary<Type,IFileStagingArtifact>>, Nullable<TimeSpan>, IEnumerable<BatchClientBehavior>)
- Source:
- CloudJob.cs
Adds tasks to a job.
public System.Threading.Tasks.Task AddTaskAsync (System.Collections.Generic.IEnumerable<Microsoft.Azure.Batch.CloudTask> tasksToAdd, Microsoft.Azure.Batch.BatchClientParallelOptions parallelOptions = default, System.Collections.Concurrent.ConcurrentBag<System.Collections.Concurrent.ConcurrentDictionary<Type,Microsoft.Azure.Batch.IFileStagingArtifact>> fileStagingArtifacts = default, TimeSpan? timeout = default, System.Collections.Generic.IEnumerable<Microsoft.Azure.Batch.BatchClientBehavior> additionalBehaviors = default);
member this.AddTaskAsync : seq<Microsoft.Azure.Batch.CloudTask> * Microsoft.Azure.Batch.BatchClientParallelOptions * System.Collections.Concurrent.ConcurrentBag<System.Collections.Concurrent.ConcurrentDictionary<Type, Microsoft.Azure.Batch.IFileStagingArtifact>> * Nullable<TimeSpan> * seq<Microsoft.Azure.Batch.BatchClientBehavior> -> System.Threading.Tasks.Task
Public Function AddTaskAsync (tasksToAdd As IEnumerable(Of CloudTask), Optional parallelOptions As BatchClientParallelOptions = Nothing, Optional fileStagingArtifacts As ConcurrentBag(Of ConcurrentDictionary(Of Type, IFileStagingArtifact)) = Nothing, Optional timeout As Nullable(Of TimeSpan) = Nothing, Optional additionalBehaviors As IEnumerable(Of BatchClientBehavior) = Nothing) As Task
Parameters
- tasksToAdd
- IEnumerable<CloudTask>
The CloudTasks to add.
- parallelOptions
- BatchClientParallelOptions
Controls the number of simultaneous parallel AddTaskCollection requests issued to the Batch service. Each AddTaskCollection request contains at most MaxTasksInSingleAddTaskCollectionRequest tasks in it. Also controls the cancellation token for the operation. If omitted, the default is used (see BatchClientParallelOptions.)
- fileStagingArtifacts
- ConcurrentBag<ConcurrentDictionary<Type,IFileStagingArtifact>>
An optional collection to receive information about the file staging process (see FilesToStage). An entry is added to the ConcurrentBag<T> for each set of tasks grouped for submission to the Batch service. Unlike single-task adds, you cannot use this parameter to customize the file staging process. For more information about the format of each entry, see IFileStagingArtifact.
- additionalBehaviors
- IEnumerable<BatchClientBehavior>
A collection of BatchClientBehavior instances that are applied to the Batch service request after the CustomBehaviors.
Returns
A Task object that represents the asynchronous operation.
Exceptions
Thrown if one or more requests to the Batch service fail.
Remarks
The add task operation runs asynchronously.
This method is not atomic; that is, it is possible for the method to start adding tasks and then fail. The collection of tasks to add is broken down into chunks of size at most MaxTasksInSingleAddTaskCollectionRequest, and an AddTaskCollection request is issued for each chunk. Requests may be issued in parallel according to the parallelOptions
.
Issuing a large number of simultaneous requests to the Batch service can incur HTTP connection restrictions. If you are performing many of these operations in parallel (or have specified a large MaxDegreeOfParallelism in the parallelOptions) and are seeing client side timeouts (a TaskCanceledException), please see http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit%28v=vs.110%29.aspx .
The progress of the operation in the face of errors is determined by AddTaskCollectionResultHandler behavior. You do not normally need to specify this behavior, as the Batch client uses a default which works in normal circumstances. If you do want to customize this behavior, specify an AddTaskCollectionResultHandler in the CustomBehaviors or additionalBehaviors
collections.
Applies to
Azure SDK for .NET