Correcting Common Async/Await Mistakes in .NET 8 - Brandon Minnick - NDC London 2024

Correcting common async/await mistakes in.NET 8, including the benefits of using `ValueTask` and `IAsyncDisposable`, and how to prevent thread blocking with `ConfigureAwait(false)`.

Key takeaways
  • The async keyword adds about 80 bytes to the compiled code.
  • The await keyword is not the same as WaitAsync or Result.
  • It’s recommended to use ValueTask instead of Task for better performance.
  • The ConfigureAwait(false) method can be used to prevent the calling thread from being blocked.
  • The IAsyncDisposable interface is new in.NET 8 and allows for asynchronous disposal of resources.
  • The IAsyncEnumerable interface is also new in.NET 8 and allows for asynchronous iteration over a sequence of values.
  • The SafeFireForget method can be used to safely fire and forget an asynchronous operation.
  • The FrozenSet and FrozenDictionary classes are new in.NET 8 and provide a way to create immutable sets and dictionaries.
  • The IAsyncStateMachine interface is used by the compiler to generate the state machine for an asynchronous method.
  • The ConfigureAwait(false) method can be used to prevent the calling thread from being blocked, but it’s not recommended to use it unless necessary.
  • The await keyword can be used to asynchronously wait for a task to complete, but it’s not the same as WaitAsync or Result.
  • The ValueTask class provides a way to represent a task that can be awaited asynchronously.
  • The IAsyncDisposable interface is used to provide a way to asynchronously dispose of resources.
  • The IAsyncEnumerable interface is used to provide a way to asynchronously iterate over a sequence of values.
  • The SafeFireForget method is used to safely fire and forget an asynchronous operation.
  • The FrozenSet and FrozenDictionary classes are used to create immutable sets and dictionaries.
  • The IAsyncStateMachine interface is used by the compiler to generate the state machine for an asynchronous method.
  • The ConfigureAwait(false) method is used to prevent the calling thread from being blocked, but it’s not recommended to use it unless necessary.
  • The await keyword is used to asynchronously wait for a task to complete, but it’s not the same as WaitAsync or Result.
  • The ValueTask class is used to represent a task that can be awaited asynchronously.
  • The IAsyncDisposable interface is used to provide a way to asynchronously dispose of resources.
  • The IAsyncEnumerable interface is used to provide a way to asynchronously iterate over a sequence of values.
  • The SafeFireForget method is used to safely fire and forget an asynchronous operation.
  • The FrozenSet and FrozenDictionary classes are used to create immutable sets and dictionaries.
  • The IAsyncStateMachine interface is used by the compiler to generate the state machine for an asynchronous method.
  • The ConfigureAwait(false) method is used to prevent the calling thread from being blocked, but it’s not recommended to use it unless necessary.
  • The await keyword is used to asynchronously wait for a task to complete, but it’s not the same as WaitAsync or Result.
  • The ValueTask class is used to represent a task that can be awaited asynchronously.
  • The IAsyncDisposable interface is used to provide a way to asynchronously dispose of resources.
  • The IAsyncEnumerable interface is used to provide a way to asynchronously iterate over a sequence of values.
  • The SafeFireForget method is used to safely fire and forget an asynchronous operation.
  • The FrozenSet and FrozenDictionary classes are used to create immutable sets and dictionaries.
  • The IAsyncStateMachine interface is used by the compiler to generate the state machine for an asynchronous method.
  • The ConfigureAwait(false) method is used to prevent the calling thread from being blocked, but it’s not recommended to use it unless necessary.
  • The await keyword is used to asynchronously wait for a task to complete, but it’s not the same as WaitAsync or Result.
  • The ValueTask class is used to represent a task that can be awaited asynchronously.
  • The IAsyncDisposable interface is used to provide a way to asynchronously dispose of resources.
  • The IAsyncEnumerable interface is used to provide a way to asynchronously iterate over a sequence of values.
  • The SafeFireForget method is used to safely fire and forget an asynchronous operation.
  • The FrozenSet and FrozenDictionary classes are used to create immutable sets and dictionaries.
  • The IAsyncStateMachine interface is used by the compiler to generate the state machine for an asynchronous method.
  • The ConfigureAwait(false) method is used to prevent the calling thread from being blocked, but it’s not recommended to use it unless necessary.
  • The await keyword is used to asynchronously wait for a task to complete, but it’s not the same as WaitAsync or Result.
  • The ValueTask class is used to represent a task that can be awaited asynchronously.
  • The IAsyncDisposable interface is used to provide a way to asynchronously dispose of resources.
  • The IAsyncEnumerable interface is used to provide a way to asynchronously iterate over a sequence of values.
  • The SafeFireForget method is used to safely fire and forget an asynchronous operation.
  • The FrozenSet and FrozenDictionary classes are used to create immutable sets and dictionaries.
  • The IAsyncStateMachine interface is used by the compiler to generate the state machine for an asynchronous method.
  • The ConfigureAwait(false) method is used to prevent the calling thread from being blocked, but it’s not recommended to use it unless necessary.
  • The await keyword is used to asynchronously wait for a task to complete, but it’s not the same as WaitAsync or Result.
  • The ValueTask class is used to represent a task that can be awaited asynchronously.
  • The IAsyncDisposable interface is used to provide a way to asynchronously dispose of resources.
  • The IAsyncEnumerable interface is used to provide a way to asynchronously iterate over a sequence of values.
  • The SafeFireForget method is used to safely fire and forget an asynchronous operation.
  • The FrozenSet and FrozenDictionary classes are used to create immutable sets and dictionaries.
  • The IAsyncStateMachine interface is used by the compiler to generate the state machine for an asynchronous method.
  • The ConfigureAwait(false) method is used to prevent the calling thread from being blocked, but it’s not recommended to use it unless necessary.
  • The await keyword is used to asynchronously wait for a task to complete, but it’s not the same as WaitAsync or Result.
  • The ValueTask class is used to represent a task that can be awaited asynchronously.
  • The IAsyncDisposable interface is used to provide a way to asynchronously dispose of resources.
  • The IAsyncEnumerable interface is used to provide a way to asynchronously iterate over a sequence of values.
  • The SafeFireForget method is used to safely fire and forget an asynchronous operation.
  • The FrozenSet and FrozenDictionary classes are used to create immutable sets and dictionaries.
  • The IAsyncStateMachine interface is used by the compiler to generate the state machine for an asynchronous method.
  • The ConfigureAwait(false) method is used to prevent the calling thread from being blocked, but it’s not recommended to use it unless necessary.
  • The await keyword is used to asynchronously wait for a task to complete, but it’s not the same as WaitAsync or Result.
  • The ValueTask class is used to represent a task that can be awaited asynchronously.
  • The IAsyncDisposable interface is used to provide a way to asynchronously dispose of resources.
  • The IAsyncEnumerable interface is used to provide a way to asynchronously iterate over a sequence of values.
  • The SafeFireForget method is used to safely fire and forget an asynchronous operation.
  • The FrozenSet and FrozenDictionary classes are used to create immutable sets and dictionaries.
  • The IAsyncStateMachine interface is used by the compiler to generate the state machine for an asynchronous method.
  • The ConfigureAwait(false) method is used to prevent the calling thread from being blocked, but it’s not recommended to use it unless necessary.
  • The await keyword is used to asynchronously wait for a task to complete, but it’s not the same as WaitAsync or Result.
  • The ValueTask class is used to represent a task that can be awaited asynchronously.
  • The IAsyncDisposable interface is used to provide a way to asynchronously dispose of resources.
  • The IAsyncEnumerable interface is used to provide a way to asynchronously iterate over a sequence of values.
  • The SafeFireForget method is used to safely fire and forget an asynchronous operation.
  • The FrozenSet and FrozenDictionary classes are used to create immutable sets and dictionaries.
  • The IAsyncStateMachine interface is used by the compiler to generate the state machine for an asynchronous method.
  • The ConfigureAwait(false) method is used to prevent the calling thread from being blocked, but it’s not recommended to use it unless necessary.
  • The await keyword is used to asynchronously wait for a task to complete, but it’s not the same as WaitAsync or Result.
  • The ValueTask class is used to represent a task that can be awaited asynchronously.
  • The IAsyncDisposable interface is used to provide a way to asynchronously dispose of resources.
  • The IAsyncEnumerable interface is used to provide a way to asynchronously iterate over a sequence of values.
  • The SafeFireForget method is used to safely fire and forget an asynchronous operation.
  • The FrozenSet and FrozenDictionary classes are used to create immutable sets and dictionaries.
  • The IAsyncStateMachine interface is used by the compiler to generate the state machine for an asynchronous method.
  • The ConfigureAwait(false) method is used to prevent the calling thread from being blocked, but it’s not recommended to use it unless necessary.
  • The await keyword is used to asynchronously wait for a task to complete, but it’s not the same as WaitAsync or Result.
  • The ValueTask class is used to represent a task that can be awaited asynchronously.
  • The IAsyncDisposable interface is used to provide a way to asynchronously dispose of resources.
  • The IAsyncEnumerable interface is used to provide a way to asynchronously iterate over a sequence of values.
  • The SafeFireForget method is used to safely fire and forget an asynchronous operation