你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

CloudJob.AddTask 方法

定义

重载

AddTask(CloudTask, IEnumerable<BatchClientBehavior>)

将单个任务添加到此 CloudJob。 若要添加多个任务,请使用 JobOperations.AddTaskAsync

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

将任务添加到作业。

AddTask(CloudTask, IEnumerable<BatchClientBehavior>)

将单个任务添加到此 CloudJob。 若要添加多个任务,请使用 JobOperations.AddTaskAsync

public System.Collections.Concurrent.ConcurrentDictionary<Type,Microsoft.Azure.Batch.IFileStagingArtifact> AddTask (Microsoft.Azure.Batch.CloudTask taskToAdd, System.Collections.Generic.IEnumerable<Microsoft.Azure.Batch.BatchClientBehavior> additionalBehaviors = default);
member this.AddTask : Microsoft.Azure.Batch.CloudTask * seq<Microsoft.Azure.Batch.BatchClientBehavior> -> System.Collections.Concurrent.ConcurrentDictionary<Type, Microsoft.Azure.Batch.IFileStagingArtifact>
Public Function AddTask (taskToAdd As CloudTask, Optional additionalBehaviors As IEnumerable(Of BatchClientBehavior) = Nothing) As ConcurrentDictionary(Of Type, IFileStagingArtifact)

参数

taskToAdd
CloudTask

要添加的 CloudTask

additionalBehaviors
IEnumerable<BatchClientBehavior>

在 之后应用于 Batch 服务请求的实例集合BatchClientBehaviorCustomBehaviors

返回

有关文件暂存过程的信息集合, (请参阅 FilesToStage) 。 有关更多信息,请参见IFileStagingArtifact

注解

每次调用此方法都会引发对 Batch 服务的请求。 因此,使用此方法添加多个任务的效率低于使用批量添加方法,并可能导致 HTTP 连接限制。 如果要并行执行其中许多操作,并且看到客户端超时 (TaskCanceledException) ,请参阅 http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit%28v=vs.110%29.aspx 或使用 AddTask(String, IEnumerable<CloudTask>, BatchClientParallelOptions, ConcurrentBag<ConcurrentDictionary<Type,IFileStagingArtifact>>, Nullable<TimeSpan>, IEnumerable<BatchClientBehavior>)

这是一个阻止操作。 有关非阻塞等效项,请参阅 AddTaskAsync(CloudTask, ConcurrentDictionary<Type,IFileStagingArtifact>, IEnumerable<BatchClientBehavior>, CancellationToken)

适用于

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

将任务添加到作业。

public void AddTask (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.AddTask : 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> -> unit
Public Sub AddTask (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)

参数

tasksToAdd
IEnumerable<CloudTask>

要添加的 CloudTask

parallelOptions
BatchClientParallelOptions

控制同时向 Batch 服务发出的并行 AddTaskCollection 请求数。 每个 AddTaskCollection 请求最多 MaxTasksInSingleAddTaskCollectionRequest 包含其中的任务。 此外,还控制操作的取消标记。 如果省略,则使用默认值, (请参阅 BatchClientParallelOptions.)

fileStagingArtifacts
ConcurrentBag<ConcurrentDictionary<Type,IFileStagingArtifact>>

用于接收有关文件暂存过程的信息的可选集合 (请参阅 FilesToStage) 。 对于要提交到 ConcurrentBag<T> Batch 服务的每个任务集,都会向 添加一个条目。 与单任务添加不同,不能使用此参数自定义文件暂存过程。 有关每个条目的格式的详细信息,请参阅 IFileStagingArtifact

timeout
Nullable<TimeSpan>

操作超时的时间量。

additionalBehaviors
IEnumerable<BatchClientBehavior>

在 之后应用于 Batch 服务请求的实例集合BatchClientBehaviorCustomBehaviors

例外

如果对 Batch 服务的一个或多个请求失败,则引发。

注解

这是一个阻止操作;有关非阻塞等效项,请参阅 AddTaskAsync(IEnumerable<CloudTask>, BatchClientParallelOptions, ConcurrentBag<ConcurrentDictionary<Type,IFileStagingArtifact>>, Nullable<TimeSpan>, IEnumerable<BatchClientBehavior>)

此方法不是原子方法;也就是说,方法可能会开始添加任务,然后失败。 要添加的任务集合最多 MaxTasksInSingleAddTaskCollectionRequest分解为大小块,并为每个区块发出 AddTaskCollection 请求。 可以根据 并行发出 parallelOptions请求。

同时向 Batch 服务发出大量请求可能会导致 HTTP 连接限制。 如果要 (并行执行其中许多操作,或者在 parallelOptions) 中指定了较大的 MaxDegreeOfParallelism,并且看到客户端超时 (TaskCanceledException) ,请参阅 http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit%28v=vs.110%29.aspx 。

遇到错误时操作的进度由 AddTaskCollectionResultHandler 行为决定。 通常不需要指定此行为,因为 Batch 客户端使用在正常情况下工作的默认值。 如果确实想要自定义此行为,请在 或 additionalBehaviors 集合中CustomBehaviors指定 AddTaskCollectionResultHandler。

适用于