I am using the following code and want to test the parallel programming, but there are some problems.
using System;
using System.Threading.Tasks;
namespace DemoParallelApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("*** Main Method Start ***");
Operation();
Console.WriteLine("*** Main Method End ***");
}
static void Operation()
{
Console.WriteLine("*** Operation Method Start ***");
var task1 = Delay(5000);
Console.WriteLine("*** Operation Method End ***");
}
static async Task<int> Delay(int ms)
{
Console.WriteLine($"Start {ms}(ms) Delay");
await Task.Delay(ms);
Console.WriteLine($"End {ms}(ms) Delay");
return ms;
}
}
}
The result is like this:
*** Main Method Start ***
*** Operation Method Start
*** Start 5000(ms) Delay
*** Operation Method End ***
*** Main Method End ***
But I think it should be like this one:
*** Main Method Start ***
*** Operation Method Start ***
Start 5000(ms) Delay
*** Operation Method End ***
*** Main Method End ***
End 5000(ms) Delay
What is wrong with it?