.net made easy[]

.NET 11 Runtime Async Explained: async/await in the Runtime

All levelsLesson 308 of 325·Production .NET·13 min read·Updated

You write async and await exactly as before. What changes in .NET 11 is who does the hard work behind them: increasingly, the runtime itself rather than code the compiler generates.

In lesson 152 you learned that await means "pause here, give the thread back, and carry on when the result is ready". In lesson 207 you saw how C# makes that possible: the compiler secretly rewrites every async method into a hidden class called a state machine, which remembers where the method paused.

That trick has served C# well since 2012, but it has costs. Every async method gets a generated class, error stack traces fill up with strange compiler-made names, and stepping through await in a debugger can wander into code you never wrote. .NET 11 takes a big step towards fixing this with runtime async.

In this lesson, you'll learn what runtime async is, what it changes and what it doesn't, why your stack traces get shorter, how to try it in a project, and why it is still marked as a preview feature.

What Is It?

The Simple Explanation

Runtime async means the .NET runtime itself knows how to pause and resume async methods. The compiler no longer has to build a hidden state-machine class for each one. You keep writing the same async and await code; the difference is underneath.

The Technical Definition

.NET 11 introduces runtime-native async (Runtime Async V2). Instead of the compiler emitting a state-machine type per async method, the runtime tracks suspension and resumption. The .NET 11 runtime libraries themselves are already compiled this way. For your own code it is a preview feature: you opt in per project with <Features>runtime-async=on</Features>, and a net11.0 project no longer needs EnablePreviewFeatures to do so. To opt a project out, set <UseRuntimeAsync>false</UseRuntimeAsync>. It also works with Native AOT and ReadyToRun compilation.

Compiler-generated async (the classic way)

  • Every async method becomes a hidden state-machine class
  • Live stack traces show extra builder and state-machine frames
  • The debugger can step into generated infrastructure
  • Extra objects and code for every async method

Runtime async (.NET 11)

  • The runtime handles pausing and resuming
  • Live stack traces show just your real methods
  • Breakpoints bind correctly and stepping over await stays in your code
  • Lower overhead and smaller generated code

Why Does It Exist?

The Problem — A Clever Trick With Side Effects

Generating a state machine for every async method works without any help from the runtime, which is why C# could add async back in 2012. But the runtime can't see what's really going on: as far as it's concerned, your method is a bunch of generated classes. That costs memory and speed, and it confuses profilers, debuggers and anyone reading a stack trace.

The Solution — Teach the Runtime About async

If the runtime understands "this method can pause and resume", it can do the job more efficiently and show tools the real call chain. .NET 11 ships that machinery, has compiled its own libraries with it to prove it works at scale, and lets you try it in your projects while it finishes maturing.

Big Picture

Your code
Unchanged: same async, await, Task and ValueTask
.NET 11 libraries
Already compiled with runtime async
Your projects
Preview opt-in: <Features>runtime-async=on</Features>
What you notice
Shorter live stack traces, smoother debugging, less overhead

How It Works

ONE await, TWO WAYS
1. YOUR METHOD REACHES await
  • The awaited task isn't finished yet, so the method must pause and free the thread.
▼
2a. CLASSIC: THE GENERATED STATE MACHINE SAVES ITS PLACE
  • A compiler-generated class stores the local variables and a "step number", then registers a continuation. The runtime only sees ordinary objects and method calls.
▼
2b. RUNTIME ASYNC: THE RUNTIME SAVES ITS PLACE
  • The runtime itself records where the method paused and what it needs to resume, reusing continuation objects and skipping locals that haven't changed.
▼
3. THE TASK COMPLETES AND THE METHOD RESUMES
  • Either way, your method continues after the await with all its variables intact. The result is identical; only the machinery differs.

Simple Example

This program awaits through three methods and prints the live stack trace from the innermost one:

using System.Diagnostics; await OuterAsync(); static async Task OuterAsync() { await Task.CompletedTask; await MiddleAsync(); } static async Task MiddleAsync() { await Task.CompletedTask; await InnerAsync(); } static async Task InnerAsync() { await Task.CompletedTask; Console.WriteLine(new StackTrace(fNeedFileInfo: true)); }

Without runtime async, the trace has 13 frames, and most of them are the state-machine plumbing:

at Program.<<Main>$>g__InnerAsync|0_2() in Program.cs:line 24 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](...) at Program.<<Main>$>g__InnerAsync|0_2() at Program.<<Main>$>g__MiddleAsync|0_1() in Program.cs:line 14 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](...) ... (8 more lines like these)

With runtime async, it shrinks to 5 frames, the real call chain:

at Program.<<Main>$>g__InnerAsync|0_2() in Program.cs:line 24 at Program.<<Main>$>g__MiddleAsync|0_1() in Program.cs:line 14 at Program.<<Main>$>g__OuterAsync|0_0() in Program.cs:line 8 at Program.<Main>$(String[] args) in Program.cs:line 3 at Program.<Main>(String[] args)

Code → Meaning → Result: The C# code is identical in both runs. Only the project setting differs. With runtime async the live stack shows exactly the methods you wrote, in the order they called each other, which is what profilers, logs and the debugger's Call Stack window now see too. (The odd-looking names such as g__InnerAsync|0_2 are how C# names local functions inside top-level statements, and the line numbers depend on where the methods sit in your file.)

Real-World Example

To try runtime async in one of your own projects, for example a test copy of a web API, add one property to the .csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net11.0</TargetFramework> <Features>runtime-async=on</Features> </PropertyGroup> </Project>

Rebuild, run your tests, and compare memory use, throughput and startup time with your normal build. Because it's a preview, a sensible plan is to try it in a development or staging environment first. Microsoft has asked for reports, positive or negative, on the throughput and size changes people see.

If a project ever needs to stay on the classic model, set <UseRuntimeAsync>false</UseRuntimeAsync> in its project file. The old DOTNET_RuntimeAsync environment variables from earlier previews have been removed, so the project setting is now the switch.

Analogy

A Bookmark Made by Hand vs Built Into the Book

Classic async is like reading a library book that has no bookmark ribbon: every time you stop, you write the page number, the paragraph and your notes on a slip of paper and tuck it in. It works, but it's extra paper and fuss, and anyone flipping through the book sees your slips everywhere.

Runtime async is a book with a built-in ribbon. Stopping and starting is part of the book itself: quicker, tidier, and the pages show only the story.

Under the Hood

Common Confusion

1. "I have to rewrite my async code" — no, the source code doesn't change

async, await, Task, ValueTask, ConfigureAwait and CancellationToken all work exactly as you learned. Runtime async changes how the compiled code runs, not what you write.

2. "Runtime async makes my code run in parallel" — no, the behaviour is the same

An await still pauses the method until the result is ready, and nothing runs on extra threads that didn't before. You get the same results with less overhead and better diagnostics, not a different concurrency model.

3. "It's preview, so .NET 11 is preview" — no, only this opt-in is

.NET 11 is a fully supported release. Runtime async for your own code is the part still marked as preview, which is why you switch it on deliberately per project.

Common Mistakes

Mistake 1 — Switching it on in production first

The mistake: Turning on runtime-async=on in the main production app because the release notes mentioned better performance.

The fix: Try it in a test or staging copy, run your full test suite, and measure. Preview features can still change between releases.

Mistake 2 — Using the old environment variables

The mistake: Setting DOTNET_RuntimeAsync from an earlier preview blog post and wondering why nothing changes.

The fix: Those environment variables were removed. Use the project properties: <Features>runtime-async=on</Features> to opt in, <UseRuntimeAsync>false</UseRuntimeAsync> to opt out.

When Should I Use It?

Mental Model

Classic async: the compiler builds a hidden state machine for every async method.
Runtime async: the runtime pauses and resumes the method itself.
Same source code, same results; shorter live stack traces and less overhead.

Remember: runtime async changes who does the work behind await, not what await means.

Key Takeaway


Check Your Understanding

Three questions on what runtime async changes, and what it leaves alone.

1. What do you need to change in your C# source code to benefit from runtime async?

Show answer

Correct: B

Why B is correct: Runtime async changes the machinery behind async/await, not the language. Your methods, tasks and awaits stay exactly as they are.

Why A is incorrect: There's no new keyword. await keeps its meaning.

Why C is incorrect: There's no RuntimeTask type. Task and ValueTask are unchanged.

Why D is incorrect: ConfigureAwait behaves as before. Nothing about it needs removing.

Reinforcement: Same code, different engine underneath.

2. How does a project opt in to runtime async in .NET 11?

Show answer

Correct: B

Why B is correct: The official opt-in is the <Features>runtime-async=on</Features> property, and a net11.0 project no longer needs EnablePreviewFeatures for it.

Why A is incorrect: The DOTNET_RuntimeAsync environment variables were removed. Project properties replaced them.

Why C is incorrect: No package is needed. The support is built into the .NET 11 runtime and compiler.

Why D is incorrect: The libraries already use it, and your projects can opt in as a preview feature.

Reinforcement: Opt in: <Features>runtime-async=on</Features>. Opt out: <UseRuntimeAsync>false</UseRuntimeAsync>.

3. Which improvement does runtime async give most visibly?

Show answer

Correct: B

Why B is correct: Without the compiler-generated state machines, tools that inspect the running stack (profilers, the debugger, new StackTrace()) see just the real call chain, as the 13-frame vs 5-frame example shows.

Why A is incorrect: Runtime async doesn't change concurrency. Code runs exactly as it did before.

Why C is incorrect: Exceptions still flow through tasks and are rethrown at await, just as you learned in the async exception lesson.

Why D is incorrect: await still pauses until the awaited task completes. That's the definition of await.

Reinforcement: Biggest visible win: honest, short live stack traces.

Runtime async improves code you've already written. The next lesson looks at code you'll want to write: the most useful new library APIs in .NET 11, from LINQ's FullJoin to running a process and capturing its output in one line.