我相信在Visual Studio中有一个技巧,你可以在监 windows 口中使用$returnvalue,如果你在调试时跳过一个函数,那么它将显示从最后一个方法返回的值。然而,这似乎只对非异步方法有效。如果我试图在等待的异步方法调用上这样做,那么它不会被填充。有没有一种机制可以在异步调用上这样做?
w46czmvw1#
异步方法不是你常用的方法,它们是状态机。此方法:
async Task Delay() => await Task.Delay(1000);
会被翻译成类似这样的东西:
[CompilerGenerated] private sealed class <Delay>d__0 : IAsyncStateMachine { public int <>1__state; public AsyncTaskMethodBuilder <>t__builder; public C <>4__this; private TaskAwaiter <>u__1; private void MoveNext() { int num = <>1__state; try { TaskAwaiter awaiter; if (num != 0) { awaiter = Task.Delay(1000).GetAwaiter(); if (!awaiter.IsCompleted) { num = (<>1__state = 0); <>u__1 = awaiter; <Delay>d__0 stateMachine = this; <>t__builder.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine); return; } } else { awaiter = <>u__1; <>u__1 = default(TaskAwaiter); num = (<>1__state = -1); } awaiter.GetResult(); } catch (Exception exception) { <>1__state = -2; <>t__builder.SetException(exception); return; } <>1__state = -2; <>t__builder.SetResult(); } [DebuggerHidden] private void SetStateMachine([System.Runtime.CompilerServices.Nullable(1)] IAsyncStateMachine stateMachine) { } [System.Runtime.CompilerServices.NullableContext(1)] [AsyncStateMachine(typeof(<Delay>d__0))] [DebuggerStepThrough] private Task Delay() { <Delay>d__0 stateMachine = new <Delay>d__0(); stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>4__this = this; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder. Task; }
1条答案
按热度按时间w46czmvw1#
异步方法不是你常用的方法,它们是状态机。
此方法:
会被翻译成类似这样的东西: