Async Task vs Async void
11 removals
80 lines
8 additions
78 lines
public class MyClass
public class MyClass
{
{
[CompilerGenerated]
[CompilerGenerated]
private sealed class <NormalAsync>d__0 : IAsyncStateMachine
private sealed class <AsyncVoid>d__0 : IAsyncStateMachine
{
{
public int <>1__state;
public int <>1__state;
public AsyncTaskMethodBuilder <>t__builder;
public AsyncVoidMethodBuilder <>t__builder;
public MyClass <>4__this;
public MyClass <>4__this;
private YieldAwaitable.YieldAwaiter <>u__1;
private YieldAwaitable.YieldAwaiter <>u__1;
private void MoveNext()
private void MoveNext()
{
{
int num = <>1__state;
int num = <>1__state;
try
try
{
{
YieldAwaitable.YieldAwaiter awaiter;
YieldAwaitable.YieldAwaiter awaiter;
if (num != 0)
if (num != 0)
{
{
awaiter = Task.Yield().GetAwaiter();
awaiter = Task.Yield().GetAwaiter();
if (!awaiter.IsCompleted)
if (!awaiter.IsCompleted)
{
{
num = (<>1__state = 0);
num = (<>1__state = 0);
<>u__1 = awaiter;
<>u__1 = awaiter;
<NormalAsync>d__0 stateMachine = this;
<AsyncVoid>d__0 stateMachine = this;
<>t__builder.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine);
<>t__builder.AwaitUnsafeOnCompleted(ref awaiter, ref stateMachine);
return;
return;
}
}
}
}
else
else
{
{
awaiter = <>u__1;
awaiter = <>u__1;
<>u__1 = default(YieldAwaitable.YieldAwaiter);
<>u__1 = default(YieldAwaitable.YieldAwaiter);
num = (<>1__state = -1);
num = (<>1__state = -1);
}
}
awaiter.GetResult();
awaiter.GetResult();
}
}
catch (Exception exception)
catch (Exception exception)
{
{
<>1__state = -2;
<>1__state = -2;
<>t__builder.SetException(exception);
<>t__builder.SetException(exception);
return;
return;
}
}
<>1__state = -2;
<>1__state = -2;
<>t__builder.SetResult();
<>t__builder.SetResult();
}
}
void IAsyncStateMachine.MoveNext()
void IAsyncStateMachine.MoveNext()
{
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
this.MoveNext();
this.MoveNext();
}
}
[DebuggerHidden]
[DebuggerHidden]
private void SetStateMachine([Nullable(1)] IAsyncStateMachine stateMachine)
private void SetStateMachine([Nullable(1)] IAsyncStateMachine stateMachine)
{
{
}
}
void IAsyncStateMachine.SetStateMachine([Nullable(1)] IAsyncStateMachine stateMachine)
void IAsyncStateMachine.SetStateMachine([Nullable(1)] IAsyncStateMachine stateMachine)
{
{
//ILSpy generated this explicit interface implementation from .override directive in SetStateMachine
//ILSpy generated this explicit interface implementation from .override directive in SetStateMachine
this.SetStateMachine(stateMachine);
this.SetStateMachine(stateMachine);
}
}
}
}
[NullableContext(1)]
[AsyncStateMachine(typeof(<AsyncVoid>d__0))]
[AsyncStateMachine(typeof(<NormalAsync>d__0))]
[DebuggerStepThrough]
[DebuggerStepThrough]
public Task NormalAsync()
public void AsyncVoid()
{
{
<NormalAsync>d__0 stateMachine = new <NormalAsync>d__0();
<AsyncVoid>d__0 stateMachine = new <AsyncVoid>d__0();
stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create();
stateMachine.<>t__builder = AsyncVoidMethodBuilder.Create();
stateMachine.<>4__this = this;
stateMachine.<>4__this = this;
stateMachine.<>1__state = -1;
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
}
}
}