c # task notes

    Program class 
    { 
        // Create Task task three ways (no return value) 
        static void the Main (String [] args) 
        { 
            // A method 
            Task Task Task1 new new = (() => 
            { 
                Console.WriteLine ( "Asynchronous method tasks "); 
                the Thread.Sleep (2000); 

            }); 
            task1.Start (); 
            Task.WaitAll (Task1); 
            // method two 
            Task.Run (() => 
            { 
                Console.WriteLine (" method two asynchronous tasks " ); 
            }); 
            // method three 
            Task.Factory.StartNew (() => 
            {
                Console.WriteLine ( "Method III: asynchronous task created through the factory objects"); 
            }); 
            Console.ReadLine (); 
        } 
    }

  

 

Guess you like

Origin www.cnblogs.com/caoruipeng/p/12013445.html