CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
System::Threading::Tasks Namespace Reference

Classes

class  Parallel
 Provides support for parallel loops and regions. More...
 
class  ParallelLoopResult
 Provides completion status of a Parallel loop. More...
 
class  ParallelOptions
 Stores options that configure the operation of methods on the Parallel class. More...
 
class  ResultTask
 A Task specialization that returns a result value upon completion. More...
 
class  ResultValueTask
 Represents a hybrid task-like type that can wrap either a direct result value or a ResultTask<T>. More...
 
class  Task
 Represents an asynchronous operation that can be awaited and composed with other tasks. More...
 
class  TaskScheduler
 Represents an object that handles the low-level work of queuing tasks onto threads. More...
 
class  ValueTask
 Provides an awaitable result of an asynchronous operation. More...
 

Enumerations

enum class  TaskStatus {
  Created = 0 , WaitingForActivation = 1 , WaitingToRun = 2 , Running = 3 ,
  WaitingForChildrenToComplete = 4 , RanToCompletion = 5 , Canceled = 6 , Faulted = 7
}
 

Functions

TaskPtr Delay (int32_t millisecondsDelay)
 Creates a task that completes after a time delay. More...
 
TaskPtr Delay (int32_t millisecondsDelay, const CancellationToken &cancellationToken)
 Creates a task that completes after a time delay and can be cancelled. More...
 
TaskPtr FromCanceled (const CancellationToken &cancellationToken)
 Creates a task that has completed due to cancellation with the specified token. More...
 
TaskPtr FromException (const Exception &exception)
 Creates a task that has completed with a specified exception. More...
 
template<typename TResult >
RTaskPtr< TResult > FromException (const Exception &exception)
 Creates a task that has completed with a specified exception and result type. More...
 
template<typename TResult >
RTaskPtr< TResult > FromResult (TResult result)
 Creates a task that has successfully completed with the specified result. More...
 
TaskPtr Run (const Action<> &action)
 Queues the specified work to run on the thread pool and returns a Task handle for that work. More...
 
TaskPtr Run (const Action<> &action, const CancellationToken &cancellationToken)
 Queues the specified work to run on the thread pool and returns a Task handle for that work. More...
 
TaskPtr Run (const Func< TaskPtr > &function)
 Queues the specified work to run on the thread pool and returns a proxy for the Task returned by the function. More...
 
template<typename TResult >
RTaskPtr< TResult > Run (const Func< TResult > &function)
 Queues the specified work to run on the thread pool and returns a Task<TResult> handle for that work. More...
 
void WaitAll (const ArrayPtr< TaskPtr > &tasks, const CancellationToken &cancellationToken)
 Waits for all of the provided Task objects to complete execution. More...
 
void WaitAll (const ArrayPtr< TaskPtr > &tasks)
 Waits for all of the provided Task objects to complete execution. More...
 
int32_t WaitAny (const ArrayPtr< TaskPtr > &tasks, const CancellationToken &cancellationToken)
 Waits for any of the provided Task objects to complete execution. More...
 
int32_t WaitAny (const ArrayPtr< TaskPtr > &tasks)
 Waits for any of the provided Task objects to complete execution. More...
 
TaskPtr WhenAll (const ArrayPtr< TaskPtr > &tasks)
 Creates a task that will complete when all of the supplied tasks have completed. More...
 
TaskPtr WhenAll (const SharedPtr< Collections::Generic::IEnumerable< TaskPtr > > &tasks)
 Creates a task that will complete when all of the supplied tasks have completed. More...
 
template<typename TResult >
RTaskPtr< ArrayPtr< TResult > > WhenAll (const SharedPtr< Collections::Generic::IEnumerable< RTaskPtr< TResult > > > &tasks)
 Creates a task that will complete when all of the supplied tasks have completed. More...
 
template<typename TResult >
RTaskPtr< ArrayPtr< TResult > > WhenAll (const ArrayPtr< RTaskPtr< TResult > > &tasks)
 Creates a task that will complete when all of the supplied tasks have completed. More...
 
RTaskPtr< TaskPtrWhenAny (const SharedPtr< Collections::Generic::IEnumerable< TaskPtr > > &tasks)
 Creates a task that will complete when any of the supplied tasks have completed. More...
 
RTaskPtr< TaskPtrWhenAny (const ArrayPtr< TaskPtr > &tasks)
 Creates a task that will complete when any of the supplied tasks have completed. More...
 
template<typename TResult >
RTaskPtr< RTaskPtr< TResult > > WhenAny (const ArrayPtr< RTaskPtr< TResult > > &tasks)
 Creates a task that will complete when any of the supplied tasks have completed. More...
 
template<typename TResult >
RTaskPtr< RTaskPtr< TResult > > WhenAny (const SharedPtr< Collections::Generic::IEnumerable< RTaskPtr< TResult > > > &tasks)
 Creates a task that will complete when any of the supplied tasks have completed. More...
 
Runtime::CompilerServices::YieldAwaitable Yield ()
 Creates an awaitable task that asynchronously yields back to the current context when awaited. More...
 

Enumeration Type Documentation

◆ TaskStatus

Enumerator
Created 
WaitingForActivation 
WaitingToRun 
Running 
WaitingForChildrenToComplete 
RanToCompletion 
Canceled 
Faulted 

Function Documentation

◆ Delay() [1/2]

TaskPtr System::Threading::Tasks::Delay ( int32_t  millisecondsDelay)

Creates a task that completes after a time delay.

Parameters
millisecondsDelayThe number of milliseconds to wait before completing the returned task, or -1 to wait indefinitely.
Returns
A task that represents the time delay.
Exceptions
System.ArgumentOutOfRangeExceptionif the millisecondsDelay argument is less than -1.

◆ Delay() [2/2]

TaskPtr System::Threading::Tasks::Delay ( int32_t  millisecondsDelay,
const CancellationToken cancellationToken 
)

Creates a task that completes after a time delay and can be cancelled.

Parameters
millisecondsDelayThe number of milliseconds to wait before completing the returned task, or -1 to wait indefinitely.
cancellationTokenThe cancellation token that can be used to cancel the delay.
Returns
A task that represents the time delay.
Exceptions
System.ArgumentOutOfRangeExceptionif the millisecondsDelay argument is less than -1.

◆ FromCanceled()

TaskPtr System::Threading::Tasks::FromCanceled ( const CancellationToken cancellationToken)

Creates a task that has completed due to cancellation with the specified token.

Parameters
cancellationTokenThe cancellation token that caused the task to be cancelled.
Returns
A cancelled task.

◆ FromException() [1/2]

TaskPtr System::Threading::Tasks::FromException ( const Exception exception)

Creates a task that has completed with a specified exception.

Parameters
exceptionThe exception with which to complete the task.
Returns
A faulted task.

◆ FromException() [2/2]

template<typename TResult >
RTaskPtr< TResult > System::Threading::Tasks::FromException ( const Exception exception)

Creates a task that has completed with a specified exception and result type.

Template Parameters
TResultThe type of the task's result.
Parameters
exceptionThe exception with which to complete the task.
Returns
A faulted task with the specified result type.

◆ FromResult()

template<typename TResult >
RTaskPtr< TResult > System::Threading::Tasks::FromResult ( TResult  result)

Creates a task that has successfully completed with the specified result.

Template Parameters
TResultThe type of the task's result.
Parameters
resultThe result value with which to complete the task.
Returns
A successfully completed task.

◆ Run() [1/4]

TaskPtr System::Threading::Tasks::Run ( const Action<> &  action)

Queues the specified work to run on the thread pool and returns a Task handle for that work.

Parameters
actionThe work to execute asynchronously.
Returns
A Task that represents the work queued to execute in the thread pool.

◆ Run() [2/4]

TaskPtr System::Threading::Tasks::Run ( const Action<> &  action,
const CancellationToken cancellationToken 
)

Queues the specified work to run on the thread pool and returns a Task handle for that work.

Parameters
actionThe work to execute asynchronously.
cancellationTokenA cancellation token that can be used to cancel the work if it has not yet started.
Returns
A Task that represents the work queued to execute in the thread pool.

◆ Run() [3/4]

TaskPtr System::Threading::Tasks::Run ( const Func< TaskPtr > &  function)

Queues the specified work to run on the thread pool and returns a proxy for the Task returned by the function.

Parameters
functionThe work to execute asynchronously, which returns a Task.
Returns
A Task that represents a proxy for the Task returned by the function.

◆ Run() [4/4]

template<typename TResult >
RTaskPtr< TResult > System::Threading::Tasks::Run ( const Func< TResult > &  function)

Queues the specified work to run on the thread pool and returns a Task<TResult> handle for that work.

Template Parameters
TResultThe type of the result returned by the task.
Parameters
functionThe work to execute asynchronously.
Returns
A Task<TResult> that represents the work queued to execute in the thread pool.

◆ WaitAll() [1/2]

void System::Threading::Tasks::WaitAll ( const ArrayPtr< TaskPtr > &  tasks)

Waits for all of the provided Task objects to complete execution.

Parameters
tasksAn array of Task instances on which to wait.

◆ WaitAll() [2/2]

void System::Threading::Tasks::WaitAll ( const ArrayPtr< TaskPtr > &  tasks,
const CancellationToken cancellationToken 
)

Waits for all of the provided Task objects to complete execution.

Parameters
tasksAn array of Task instances on which to wait.
cancellationTokenA CancellationToken to observe while waiting for the tasks to complete.
Exceptions
System.OperationCanceledExceptionif the cancellationToken is cancelled.

◆ WaitAny() [1/2]

int32_t System::Threading::Tasks::WaitAny ( const ArrayPtr< TaskPtr > &  tasks)

Waits for any of the provided Task objects to complete execution.

Parameters
tasksAn array of Task instances on which to wait.
Returns
The index of the completed task in the tasks array.

◆ WaitAny() [2/2]

int32_t System::Threading::Tasks::WaitAny ( const ArrayPtr< TaskPtr > &  tasks,
const CancellationToken cancellationToken 
)

Waits for any of the provided Task objects to complete execution.

Parameters
tasksAn array of Task instances on which to wait.
cancellationTokenA CancellationToken to observe while waiting for the tasks to complete.
Returns
The index of the completed task in the tasks array.
Exceptions
System.OperationCanceledExceptionif the cancellationToken is cancelled.

◆ WhenAll() [1/4]

template<typename TResult >
RTaskPtr< ArrayPtr< TResult > > System::Threading::Tasks::WhenAll ( const ArrayPtr< RTaskPtr< TResult > > &  tasks)

Creates a task that will complete when all of the supplied tasks have completed.

Template Parameters
TResultThe type of the completed tasks' results.
Parameters
tasksThe tasks to wait on for completion.
Returns
A task that returns an array of all the results when all tasks complete.

◆ WhenAll() [2/4]

TaskPtr System::Threading::Tasks::WhenAll ( const ArrayPtr< TaskPtr > &  tasks)

Creates a task that will complete when all of the supplied tasks have completed.

Parameters
tasksThe tasks to wait on for completion.
Returns
A task that represents the completion of all of the supplied tasks.

◆ WhenAll() [3/4]

template<typename TResult >
RTaskPtr< ArrayPtr< TResult > > System::Threading::Tasks::WhenAll ( const SharedPtr< Collections::Generic::IEnumerable< RTaskPtr< TResult > > > &  tasks)

Creates a task that will complete when all of the supplied tasks have completed.

Template Parameters
TResultThe type of the completed tasks' results.
Parameters
tasksThe tasks to wait on for completion.
Returns
A task that returns an array of all the results when all tasks complete.

◆ WhenAll() [4/4]

TaskPtr System::Threading::Tasks::WhenAll ( const SharedPtr< Collections::Generic::IEnumerable< TaskPtr > > &  tasks)

Creates a task that will complete when all of the supplied tasks have completed.

Parameters
tasksThe tasks to wait on for completion.
Returns
A task that represents the completion of all of the supplied tasks.

◆ WhenAny() [1/4]

template<typename TResult >
RTaskPtr< RTaskPtr< TResult > > System::Threading::Tasks::WhenAny ( const ArrayPtr< RTaskPtr< TResult > > &  tasks)

Creates a task that will complete when any of the supplied tasks have completed.

Template Parameters
TResultThe type of the completed task's result.
Parameters
tasksThe tasks to wait on for completion.
Returns
A task that returns the first completed task when any task completes.

◆ WhenAny() [2/4]

RTaskPtr< TaskPtr > System::Threading::Tasks::WhenAny ( const ArrayPtr< TaskPtr > &  tasks)

Creates a task that will complete when any of the supplied tasks have completed.

Parameters
tasksThe tasks to wait on for completion.
Returns
A task that represents the completion of one of the supplied tasks.

◆ WhenAny() [3/4]

template<typename TResult >
RTaskPtr< RTaskPtr< TResult > > System::Threading::Tasks::WhenAny ( const SharedPtr< Collections::Generic::IEnumerable< RTaskPtr< TResult > > > &  tasks)

Creates a task that will complete when any of the supplied tasks have completed.

Template Parameters
TResultThe type of the completed task's result.
Parameters
tasksThe tasks to wait on for completion.
Returns
A task that returns the first completed task when any task completes.

◆ WhenAny() [4/4]

RTaskPtr< TaskPtr > System::Threading::Tasks::WhenAny ( const SharedPtr< Collections::Generic::IEnumerable< TaskPtr > > &  tasks)

Creates a task that will complete when any of the supplied tasks have completed.

Parameters
tasksThe tasks to wait on for completion.
Returns
A task that represents the completion of one of the supplied tasks.

◆ Yield()

Runtime::CompilerServices::YieldAwaitable System::Threading::Tasks::Yield ( )

Creates an awaitable task that asynchronously yields back to the current context when awaited.

Returns
A YieldAwaitable that can be awaited to yield control.

This method is useful for forcing an asynchronous method to yield control, allowing other pending work to be processed before continuing.