Beispiel #1
0
 private static void DemoTaskWhereTheOuputIsUsed()
 {
     var task = Task<string>.Factory.StartNew(() =>
     {
         var messageGenerator = new MessageGenerator();
         return messageGenerator.GenerateMessage("Erik", 5);
     });
     var result = task.Result; // This will block on its own, no need to call Wait
     Log<Program>.Info(result);
 }
Beispiel #2
0
 private static void ContinueWithDemo()
 {
     Task.Factory.StartNew(() =>
         {
             Log<Program>.Debug("Entering first task");
             var messageGenerator = new MessageGenerator();
             string theMessage = messageGenerator.GenerateMessage("my original message (after sleeping 5 seconds)", 5);
             new MessageWriter().WriteMessage(theMessage);
             return theMessage;
         })
     .ContinueWith((s) =>
         {
             Log<Program>.Debug("Entering second task");
             var messageWriter = new MessageWriter();
             messageWriter.WriteMessage(s.Result + " now appended with another message");
         });
 }