static void Main(string[] args)
{
  Task t1 = AsynchronyWithAwait1();
  t1.Wait();

  //Task t2 = AsynchronyWithAwait2();
  //t2.Wait();
}

async static Task AsynchronyWithAwait1()
{
  Task result1 = GetInfoAsync("A", int.MaxValue);
  Task result2 = GetInfoAsync("B", int.MaxValue / 3);
  Task result3 = Task.WhenAll(result1, result2);
  try
  {
    var r = await result3;
    foreach (var result in r)
    {
      Console.WriteLine(result);
    }
  }
  catch
  {
    var ae = result3.Exception.Flatten();
    var exceptions = ae.InnerExceptions;
    foreach (var exception in exceptions)
    {
      Console.WriteLine(exception);
    }
  }
}

async static Task AsynchronyWithAwait2()
{
  try
  {
    Task result1 = GetInfoAsync("A", int.MaxValue);
    Task result2 = GetInfoAsync("B", int.MaxValue / 3);
    string[] r = await Task.WhenAll(result1, result2);
    foreach (var result in r)
    {
      Console.WriteLine(result);
    }
  }
  catch (Exception exception)
  {
    Console.WriteLine(exception);
  }
}

static async Task GetInfoAsync(string name, int row)
{
  long number = 1;
  for (int i = 0; i < row; i++)
  {
    number += i;
  }
  await Task.Delay(1);
  if (name == "A")
  {
    int a = 0;
    int b = 1 / a;
  }

  if (name == "B")
  {
    string a = "a";
    int b = 1 / Convert.ToInt32(a);
  }
  return $"Task {name} is running on a thread id {Thread.CurrentThread.ManagedThreadId}. " +
    $"Is thread pool thread:{Thread.CurrentThread.IsThreadPoolThread},number={number}";
}