Advertisement
ivandrofly

TPL_part_1_setting_task_state

Jan 19th, 2015
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace TPL_part_1_setting_task_state
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //Action delegate
  14.             Task task1 = new Task(new Action<object>(HelloConsole), "Task 1");
  15.  
  16.             //anonymous function
  17.             Task task2 = new Task(delegate(object obj)
  18.             {
  19.                 HelloConsole(obj);
  20.             }, "Task 2");
  21.  
  22.             //lambda expression
  23.             Task task3 = new Task((obj) => HelloConsole(obj), "Task 3");
  24.  
  25.             task1.Start();
  26.             task2.Start();
  27.             task3.Start();
  28.  
  29.             Console.WriteLine("Main method complete. Press any key to finish.");
  30.             Console.ReadKey();
  31.         }
  32.  
  33.         static void HelloConsole(object message)
  34.         {
  35.             Console.WriteLine("Hello: {0}", message);
  36.         }
  37.     }
  38. }
  39. //http://www.c-sharpcorner.com/UploadFile/f9f215/parallel-programming-part-1-introducing-task-programming-l/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement