共用方式為


JobOperations.AddTaskAsync Method

Definition

Overloads

AddTaskAsync(String, CloudTask, ConcurrentDictionary<Type,IFileStagingArtifact>, IEnumerable<BatchClientBehavior>, CancellationToken)

Adds a single task to a job. To add multiple tasks, use JobOperations.AddTaskAsync.

AddTaskAsync(String, IEnumerable<CloudTask>, BatchClientParallelOptions, ConcurrentBag<ConcurrentDictionary<Type,IFileStagingArtifact>>, Nullable<TimeSpan>, IEnumerable<BatchClientBehavior>)

Adds tasks to a job.

AddTaskAsync(String, CloudTask, ConcurrentDictionary<Type,IFileStagingArtifact>, IEnumerable<BatchClientBehavior>, CancellationToken)

Source:
JobOperations.cs

Adds a single task to a job. To add multiple tasks, use JobOperations.AddTaskAsync.

public System.Threading.Tasks.Task AddTaskAsync (string jobId, 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 : string * 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 (jobId As String, 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

jobId
String

The id of the job to which to add the task.

taskToAdd
CloudTask

The CloudTask to add.

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 object 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, please see http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit%28v=vs.110%29.aspx or use the multiple-task overload of AddTaskAsync.

The add task operation runs asynchronously.

Applies to

AddTaskAsync(String, IEnumerable<CloudTask>, BatchClientParallelOptions, ConcurrentBag<ConcurrentDictionary<Type,IFileStagingArtifact>>, Nullable<TimeSpan>, IEnumerable<BatchClientBehavior>)

Source:
JobOperations.cs

Adds tasks to a job.

public System.Threading.Tasks.Task AddTaskAsync (string jobId, 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 : string * 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 (jobId As String, 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

jobId
String

The id of the job to which to add the tasks.

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.

timeout
Nullable<TimeSpan>

The amount of time after which the operation times out.

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, 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