Edit

Share via


TaskExtensions.GetResultOrDefault Method

Definition

Overloads

GetResultOrDefault(Task)

Gets the result of a Task if available, or null otherwise.

GetResultOrDefault<T>(Task<T>)

Gets the result of a Task<TResult> if available, or default otherwise.

GetResultOrDefault(Task)

Gets the result of a Task if available, or null otherwise.

public static object? GetResultOrDefault (this System.Threading.Tasks.Task task);
static member GetResultOrDefault : System.Threading.Tasks.Task -> obj
<Extension()>
Public Function GetResultOrDefault (task As Task) As Object

Parameters

task
Task

The input Task instance to get the result for.

Returns

The result of task if completed successfully, or default otherwise.

Remarks

This method does not block if task has not completed yet. Furthermore, it is not generic and uses reflection to access the Result property and boxes the result if it's a value type, which adds overhead. It should only be used when using generics is not possible.

Applies to

GetResultOrDefault<T>(Task<T>)

Gets the result of a Task<TResult> if available, or default otherwise.

public static T? GetResultOrDefault<T> (this System.Threading.Tasks.Task<T?> task);
static member GetResultOrDefault : System.Threading.Tasks.Task<'T> -> 'T
<Extension()>
Public Function GetResultOrDefault(Of T) (task As Task(Of T)) As T

Type Parameters

T

The type of Task<TResult> to get the result for.

Parameters

task
Task<T>

The input Task<TResult> instance to get the result for.

Returns

T

The result of task if completed successfully, or default otherwise.

Remarks

This method does not block if task has not completed yet.

Applies to