Hi ,
I am trying to understand the actual use of asyn/await in c# and have gone through few articles and tried with an example as below.
- class Program
- {
- static void Main(string[] args)
- {
- Program p = new Program();
- p.MethodOne();
- p.MethodTwo();
- p.MethodThree();
- }
-
- public void MethodOne()
- {
- Console.WriteLine("methodone has been called");
- }
- public async Task MethodTwo()
- {
- Task<string> delayingMethodCall = new Task<string>(DelayingMethod);
- Console.WriteLine("methodTwo call started");
- string message = await delayingMethodCall;
- Console.WriteLine(message);
- Console.WriteLine("methodTwo called");
- Console.ReadKey();
- }
- public void MethodThree()
- {
- Console.WriteLine("methodThree has been called");
- }
- public string DelayingMethod()
- {
- System.Threading.Thread.Sleep(5000);
- return "Delayed Process is done";
- }
- }
I am able to see third method's result , but the code after string message = await delayingMethodCall;
is not executing.
Can someone explain me the issue here?
Thanks in Advance
Ravi.