{I+=codeWee;}
[C#] Async Sample
using System;
using System.Threading;
using System.Threading.Tasks;

static void Main(string[] args)
{

	TestAsync((n)=> { 
		Console.WriteLine("final value : {0}", n);
	});

	int n = 0;
	while (n < 10)
	{
		Console.WriteLine("k: {0}", n);
		n++;
		Thread.Sleep(1);
	}

	Console.ReadKey();
}

static async void TestAsync(Action<int> end)
{
	int a = await A();
	end?.Invoke(a);
	int b = await B();
	end?.Invoke(b);

}

static Task<int> A()
{
	return Task.Run<int>(() => { 
		int n = 0;
		while(n<10)
		{
			Console.WriteLine("a: {0}", n);
			n++;
			Thread.Sleep(1);
		}
		return n;
	});
}
static Task<int> B()
{
	return Task.Run<int>(() => {
		int n = 0;
		while (n < 10)
		{
			Console.WriteLine("b: {0}", n);
			n++;
			Thread.Sleep(1);
		}
		return n;
	});
}
HTML | PHP | C++ | DirectX11 | Javascript | C# | HTML5 | ASP | SQL | General | CSS | Oculus Rift | Unity3d | Virtools SDK | Tip | NSIS | PowerShell | node.js | Web API | RTSP | All
Copyright© 2016 CodeWee.com All rights reserved.