linux-packaging-mono/mcs/tests/test-async-01.cs
Jo Shields 8b9b85e7f5 Imported Upstream version 3.10.0
Former-commit-id: 172c8e3c300b39d5785c7a3e8dfb08ebdbc1a99b
2014-10-04 11:27:48 +01:00

58 lines
958 B
C#

using System;
using System.Threading;
using System.Threading.Tasks;
class Program
{
static ManualResetEvent master_mre = new ManualResetEvent (false);
static ManualResetEvent async_mre = new ManualResetEvent (false);
static int pos;
public static int Main ()
{
pos = 0;
TestAsync ();
if (pos != 1)
throw new ApplicationException (pos.ToString ());
pos = 2;
master_mre.Set ();
if (!async_mre.WaitOne (3000))
return 1;
if (pos != 4)
throw new ApplicationException (pos.ToString ());
return 0;
}
static async void TestAsync ()
{
pos = 1;
await RunAsync ().ConfigureAwait (false);
if (pos != 3)
throw new ApplicationException (pos.ToString ());
pos = 4;
async_mre.Set ();
}
static Task RunAsync ()
{
return Task.Factory.StartNew (() => {
master_mre.WaitOne ();
Console.WriteLine ("Hello async");
if (pos != 2)
throw new ApplicationException (pos.ToString ());
pos = 3;
});
}
}