The problem is that you do not wait for the completion of tasks, so the program terminates (no more than synchronous code blocking).
If you want tasks to run simultaneously, do this instead:
public static void Run() { Task<int> i = Print1(); Task<int> k = Print2(); Task.WaitAll(i, k); }
Another way to wait for the completion of these tasks would be to:
public static async Task Run() { Task<int> i = Print1(); Task<int> k = Print2(); await Task.WhenAll(i, k); } public static void Main(string[] args) { Run().GetAwaiter().GetResult(); }
source share