TaskExtensions.GetResultOrDefault Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
GetResultOrDefault(Task) |
Gets the result of a Task if available, or |
GetResultOrDefault<T>(Task<T>) |
Gets the result of a Task<TResult> if available, or |
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
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
The result of task
if completed successfully, or default
otherwise.
Remarks
This method does not block if task
has not completed yet.