All skills
github avatar

/csharp-async

@90921cc official
by githubgithub/awesome-copilot40k stars
5,040

Get best practices for C# async programming

Use this Skill: https://skilld.dev/gh/github/awesome-copilot/csharp-async

This session only. Nothing lands on disk.

SKILL.md

≈14 tokens always: the name and description. ≈444 when used: this file.

C# Async Programming Best Practices

Your goal is to help me follow best practices for asynchronous programming in C#.

Naming Conventions

  • Use the 'Async' suffix for all async methods
  • Match method names with their synchronous counterparts when applicable (e.g., GetDataAsync() for GetData())

Return Types

  • Return Task<T> when the method returns a value
  • Return Task when the method doesn't return a value
  • Consider ValueTask<T> for high-performance scenarios to reduce allocations
  • Avoid returning void for async methods except for event handlers

Exception Handling

  • Use try/catch blocks around await expressions
  • Avoid swallowing exceptions in async methods
  • Use ConfigureAwait(false) when appropriate to prevent deadlocks in library code
  • Propagate exceptions with Task.FromException() instead of throwing in async Task returning methods

Performance

  • Use Task.WhenAll() for parallel execution of multiple tasks
  • Use Task.WhenAny() for implementing timeouts or taking the first completed task
  • Avoid unnecessary async/await when simply passing through task results
  • Consider cancellation tokens for long-running operations

Common Pitfalls

  • Never use .Wait(), .Result, or .GetAwaiter().GetResult() in async code
  • Avoid mixing blocking and async code
  • Don't create async void methods (except for event handlers)
  • Always await Task-returning methods

Implementation Patterns

  • Implement the async command pattern for long-running operations
  • Use async streams (IAsyncEnumerable<T>) for processing sequences asynchronously
  • Consider the task-based asynchronous pattern (TAP) for public APIs

When reviewing my C# code, identify these issues and suggest improvements that follow these best practices.

Source: SKILL.md on GitHub

2 warnings16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides a set of best practices and guidelines for C# asynchronous programming. No malicious code, prompt injections, or security vulnerabilities were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    1/1 file flagged

  • ZeroLeaks5mo

    1 finding · Score: 69/100

Signed by skilld at 90921cc. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 18 hours ago.

Activeupdated 5 months ago
  • Performance
  • csharp
  • async
  • task
  • await
  • best-practices
  • exception-handling
  • cancellation

README badge

README badge for github/awesome-copilot/csharp-async

Provides guidance on C# async/await best practices including naming conventions, return types, exception handling, and common pitfalls. Helps review code for issues like async void methods, blocking calls in async contexts, and improper use of Task.Result or .Wait().

Generated from the current SKILL.md.

Does this skill cover async/await syntax or just best practices?
This skill focuses on best practices and patterns for C# async programming, including naming conventions, return types, exception handling, and common pitfalls. It assumes you already know async/await syntax.
When should I use ValueTask instead of Task?
Use ValueTask<T> in high-performance scenarios where you want to reduce heap allocations, particularly for methods that complete synchronously most of the time.
Why does this skill discourage async void methods?
Async void methods are difficult to track and can make exception handling unpredictable. They should only be used for event handlers; all other async methods should return Task or Task<T>.
What is ConfigureAwait(false) and when should I use it?
ConfigureAwait(false) prevents capturing the current synchronization context, reducing deadlock risk in library code. Use it in reusable libraries unless you specifically need to resume on the original context.
Does this skill address cancellation tokens?
Yes, the skill recommends using cancellation tokens for long-running operations as part of performance and reliability best practices.

Generated from the current SKILL.md. These answers refresh after source changes.