Advertisement
ivandrofly

TPL_part_1_creating_simple_tasks

Jan 19th, 2015
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 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_creating_simple_tasks
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //Action delegate
  14.             Task task1 = new Task(new Action(HelloConsole));
  15.  
  16.             //anonymous function
  17.             Task task2 = new Task(delegate
  18.             {
  19.                 HelloConsole();
  20.             });
  21.            
  22.             //lambda expression
  23.             Task task3 = new Task(() => HelloConsole());                      
  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.         static void HelloConsole()
  33.         {
  34.             Console.WriteLine("Hello Task");
  35.         }
  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