-1

The Following code does not display the resutl:

static void Main(string[] args)
{
    Task<DayOfWeek> taskA = Task.Run(() => DateTime.Today.DayOfWeek);
    Task continuation = taskA.ContinueWith(antecedent => Console.WriteLine("\n\nToday is {0}.", antecedent.Result));
}

This can be solved by:

try
{
      taskA.Wait();
      continuation.Wait();
}
catch (AggregateException ae)
{
  foreach (var ex in ae.InnerExceptions)
  Console.WriteLine(ex.Message);
}
Bah Man
  • 63
  • 4
  • 2
    Possible duplicate of [Why is the console window closing immediately without displaying my output?](https://stackoverflow.com/questions/8868338/why-is-the-console-window-closing-immediately-without-displaying-my-output) – Camilo Terevinto Dec 04 '17 at 11:29

1 Answers1

1

Add Console.ReadKey() at the and of Main because you program exits before task prints anything.

Backs
  • 24,430
  • 5
  • 58
  • 85