Skip to content

Use ConfigureAwaitOptions.SuppressThrowing for graceful async cleanup (Polyfill 10.3.0) #431

@sliekens

Description

@sliekens

Background

Polyfill 10.3.0 (included in #430) adds a polyfill for the ConfigureAwaitOptions enum introduced in .NET 8. This enum is now available on all target frameworks including netstandard2.0 and net462.

Opportunity

The library currently has 527 .ConfigureAwait(false) call sites. ConfigureAwait(false) remains the right choice for the general case, but ConfigureAwaitOptions unlocks one new capability worth evaluating:

ConfigureAwaitOptions.SuppressThrowing

Available via the polyfill on pre-net8 targets, this option silently absorbs exceptions from an awaited Task instead of re-throwing them — equivalent to wrapping every awaited call in a try/catch and discarding the exception. It is intended for disposal and cleanup paths where a cancellation or failure should not propagate.

Example patterns to look for:

// Cleanup/dispose paths that catch and discard OperationCanceledException
try
{
    await someTask.ConfigureAwait(false);
}
catch (OperationCanceledException) { }

// Fire-and-forget completions where the caller doesn't want exceptions surfaced

Could become:

await someTask.ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing);

Action

Audit the existing async code for any try/catch patterns around ConfigureAwait(false) that swallow OperationCanceledException or similar. Replace with SuppressThrowing where it makes the intent clearer.

Reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions