Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Diagnostics;
- using System.Threading;
- using System.Threading.Tasks;
- namespace TestAcync
- {
- class Program
- {
- class Foo
- {
- public async void Do()
- {
- Console.WriteLine("Enter your name: ");
- string name = Console.ReadLine();
- Stopwatch sw = Stopwatch.StartNew();
- string s = await AsyncHello(name);
- sw.Stop();
- Console.WriteLine(string.Format("{0}, Ellapsed {1} ms", s, sw.ElapsedMilliseconds));
- Console.ReadKey();
- }
- public Task<string> AsyncHello(string name)
- {
- var task = new Task<string>(() =>
- {
- Thread.Sleep(1000);
- return string.Format("Hi, {0}", name);
- });
- task.Start();
- return task;
- }
- }
- static void Main(string[] args)
- {
- var foo = new Foo();
- foo.Do();
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment