A day with .Net

My day to day experince in .net

Creating and starting task

Posted by vivekcek on August 19, 2012

In this post i mentioned the various method to create and start a task

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StartTask
    class Program
        static void Main(string[] args)
            //Using Action
            Task t1 = new Task(new Action(SayHello));

            //Using delegate
            Task t2 = new Task(delegate { SayHello(); });

            //Lambda Expression
            Task t3 = new Task(() => SayHello());

            //Anonymous Metod
            Task t4 = new Task(() => { Console.WriteLine("Hello"); });


            //No need to call any start method
            Task.Factory.StartNew(() => SayHello());

        static void SayHello()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s