Struct NonDisposableTask<T>
Used to convert a Task<TResult> into an awaitable that that does not
implement IDisposable. This is useful for avoiding confusion
and hard to debug problems when async methods return an IDisposable
intended to be referenced in a using
statement. It is very easy to forget
the await
keyword in this situation and because Task<TResult>
also implements IDisposable, there will be no compiler error
or warning. Wrapping the task with this structure addresses this.
Namespace: Neon.Tasks
Assembly: Neon.Common.dll
Syntax
public struct NonDisposableTask<T>
Type Parameters
Name | Description |
---|---|
T | The task result type. |
Constructors
NonDisposableTask(Task<T>)
Constructor.
Declaration
public NonDisposableTask(Task<T> task)
Parameters
Type | Name | Description |
---|---|---|
Task<T> | task | The task being wrapped. |
Methods
GetAwaiter()
Returns the task's awaiter.
Declaration
public TaskAwaiter<T> GetAwaiter()
Returns
Type | Description |
---|---|
TaskAwaiter<T> |