Below code output is this:
0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
I should make the output mixed like this:
01234X5X678XX...
I mean both methods should be started asynchronously instead of one starting after the first one finished completely. Where to modify in below code to achieve this?
using System;
using System.Threading.Tasks;
namespace ConsoleApplication36
{
class Program
{
public static void CountForward()
{
for (int i = 0; i < 100; i++) { Console.Write(i); }
}
public static void PrintX()
{
for (int i = 0; i < 100; i++) { Console.Write("X"); }
}
public async Task RunAsync()
{
Task t1 = Task.Run(() => CountForward());
Task t2 = Task.Run(() => PrintX());
Task[] tasks = { t1, t2 };
await Task.WhenAll(tasks);
}
static void Main(string[] args)
{
Task t = new Program().RunAsync();
t.Wait();
}
}
}