Hi,
In attempting to resolve an async issue I'm having, I've discovered some strange behavior in the NUnit test runner:
[Test]
public async void async_test_1()
{
await SomeAsyncThing();
System.Diagnostics.Debug.WriteLine("Finished execution.");
}
[Test]
public async Task async_test_2()
{
await SomeAsyncThing();
System.Diagnostics.Debug.WriteLine("Finished execution.");
}
private Task SomeAsyncThing()
{
return Task.Run(() =>
{
System.Diagnostics.Debug.WriteLine("Executing.");
return true;
});
}
Running async_test_1
works fine. Running async_test_2
blocks. It outputs "Executing"
and then hangs with this stack trace:
System.Threading.WaitHandle.WaitOne_internal () in
System.Threading.WaitHandle.WaitOne (millisecondsTimeout=-1, exitContext=false) in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading/WaitHandle.cs:379
System.Threading.ManualResetEventSlim.Wait (millisecondsTimeout=-1, cancellationToken=The vm is not suspended.) in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading/ManualResetEventSlim.cs:189
System.Threading.Tasks.Task.WaitCore (millisecondsTimeout=-1, cancellationToken=The vm is not suspended., runInline=true) in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/Task.cs:699
System.Threading.Tasks.Task.Wait (millisecondsTimeout=-1, cancellationToken=The vm is not suspended.) in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/Task.cs:672
System.Threading.Tasks.Task.Wait () in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading.Tasks/Task.cs:649
The only syntactic difference between the two is that test 1 is declared as void
whilst test 2 is declared as returning Task
.
Any thoughts?