How I can see the Async state machine (async/await under the hood) with the help of DotPeek?

巧了我就是萌 提交于 2020-12-13 03:30:17

问题


I'm watching a video lesson, where the author talking about async/await under the hood. He shows prepared and decompiled code. I want to do the same from scratch. I mean, decompile some C# compiled file with the help of, from example, DotPeek. So I have the following simple example:

class Program
{
    public static async Task KekAsync()
    {
        Console.WriteLine("Current thread id before await {0}", Thread.CurrentThread.ManagedThreadId);
        await Task.Delay(200);
        Console.WriteLine("Current thread id after await {0}", Thread.CurrentThread.ManagedThreadId);
        await Task.Delay(200);
        Console.WriteLine("Current thread id after await again {0}", Thread.CurrentThread.ManagedThreadId);
        await Task.Delay(200);
        Console.WriteLine("Current thread id after await again and again {0}", Thread.CurrentThread.ManagedThreadId);

    }

    static async Task Main(string[] args)
    {
        await KekAsync();
    }
}

In the DotPeek settings I have the following:

But I don't see code generation result. I see async and await.

DotPeek just shows me my source code. But I would like to see implementation of Async state machine. Result of the code generation. I used .NET Core 3.1 and the last version of .NET Framework. Both give me the same result. Am I miss something?


回答1:


So, the answer is simple. Right click on the file -> Decompiled Sources



来源:https://stackoverflow.com/questions/63783101/how-i-can-see-the-async-state-machine-async-await-under-the-hood-with-the-help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!