async-await- Example C# with Example



async-await- Example C# with Example

 using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace CSharpMultiThreading
{
	static class MyClass
	{
		public static async Task DoWorkAsync()
		{ 
			await Task.Run(() => Console.WriteLine(5.ToString()));
			
			Console.WriteLine((await Task.Run(() => 6)).ToString());
			
			await Task.Run(() => Task.Run(() => Console.WriteLine(7.ToString())));
			
			int value = await Task.Run(() => Task.Run(() => 8));
			Console.WriteLine(value.ToString());
		}
	}

	class Program
	{
		static void Main()
		{
			Task t = MyClass.DoWorkAsync();
			t.Wait();
			Console.WriteLine("Press Enter key to exit");
			Console.Read();
		}
	}
} 

0 Comment's

Comment Form