0
static void Main(string[] args)
{ print(); }

static async void print()
{
    try
    {
        await Task.Factory.StartNew(() =>
        {
            Thread.Sleep(3000);
            Console.WriteLine("3");
            Debug.Write("3");
        });
    }
    catch (Exception)
    { }
    Console.Read();
}

Console splashed without any error occurs!

Balagurunathan Marimuthu
  • 2,927
  • 4
  • 31
  • 44
xudong
  • 25
  • 1
  • 7

1 Answers1

0

It happens because print method is called in parallel so main goes on and since there is nothing else to do, it returns. After main is finished program exits.

If you want it to wait for print method, change it so it returns Task instead of void and then wait that task in Main method:

static void Main(string[] args)
{ print().Wait(); }

static async Task print() {...}
Shadowed
  • 956
  • 7
  • 19