Show / Hide Table of Contents

Class ForEachTask<T>

A task that performs an operation once for each element of a collection.

Inheritance
Object
TaskBase
ForEachTask<T>
Implements
ITask
Inherited Members
TaskBase.CancellationToken
TaskBase.CredentialProvider
TaskBase.Run(CancellationToken, ICredentialProvider, IProgress<TaskSnapshot>)
TaskBase.Tag
TaskBase.CanCancel
TaskBase.State
TaskBase.UnitsProcessed
TaskBase.UnitsTotal
Namespace: NanoByte.Common.Tasks
Assembly: NanoByte.Common.dll
Syntax
public sealed class ForEachTask<T> : TaskBase, ITask
Type Parameters
Name Description
T

Constructors

ForEachTask(String, IEnumerable<T>, Action<T>)

Creates a new for-each task.

Declaration
public ForEachTask(string name, IEnumerable<T> target, Action<T> work)
Parameters
Type Name Description
String name

A name describing the task in human-readable form.

IEnumerable<T> target

A list of objects to execute work for. Cancellation is possible between two elements.

Action<T> work

The code to be executed once per element in target. May throw WebException, IOException or OperationCanceledException.

Properties

Name

A name describing the task in human-readable form.

Declaration
public override string Name { get; }
Property Value
Type Description
String
Overrides
TaskBase.Name

UnitsByte

true if UnitsProcessed and UnitsTotal are measured in bytes; false if they are measured in generic units.

Declaration
protected override bool UnitsByte { get; }
Property Value
Type Description
Boolean
Overrides
TaskBase.UnitsByte

Methods

Execute()

The actual code to be executed.

Declaration
protected override void Execute()
Overrides
TaskBase.Execute()
Remarks

State is automatically set to Started before calling this method, to Complete after a successful exit and to an appropriate error state in case on an exception. You can set additional TaskStates during execution.

Exceptions
Type Condition
OperationCanceledException

The operation was canceled.

IOException

The task ended with IOError.

WebException

The task ended with WebError.

Implements

ITask

Extension Methods

UpdateUtils.To<TIn, TOut>(TIn, Func<TIn, TOut>)
JsonStorage.SaveJson<T>(T, Stream)
JsonStorage.SaveJson<T>(T, String)
JsonStorage.ToJsonString<T>(T)
JsonStorage.ReparseAsJson<T>(Object)
JsonStorage.ReparseAsJson<T>(Object, T)
XmlStorage.SaveXml(Object, Stream, String)
XmlStorage.SaveXml<T>(T, String, String)
XmlStorage.ToXmlString(Object, String)
ConversionUtils.ConvertToString<TType>(TType)
In This Article
Back to top Copyright Bastian Eicher