Index of every page on this site: llms.txt
All skills
github avatar

/csharp-async

@f10fdb8 official
by githubgithub/awesome-copilot41k stars
5,399
Run it yourself

Get best practices for C# async programming

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

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

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

How this Skill uses context

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈58 characters, or 0.7%.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

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

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

2 warnings2mo5 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

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

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

  • Runlayer8mo

    1/1 file flagged

  • ZeroLeaks7mo

    1 finding · Score: 69/100

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

Last checked against GitHub yesterday.

Activeupdated 7 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.