{I+=codeWee;}
[C#] Task Sample
Action action1 = () => { Console.WriteLine("Hello Action"); };
Task t1 = new Task(action1);
t1.Start();
 
Action<object> action2 = (objectParam) => { Console.WriteLine("Hello Action<object> {0}", objectParam.ToString()); };
Task t2 = new Task(action2, objectParam);
t2.Start();
 
Func<string> func1 = () => { return "Hello Func"; };
Task<string> t3 = new Task<string>(func1);
t3.Start();
 
Func<object, string> func2 = (objectParam) => { return objectParam.ToString(); };
Task<string> t4 = new Task<string>(func2, objectParam);
t4.Start();

====================

Action action1 = () => { Console.WriteLine("Hello Action"); };
Task.Factory.StartNew(action1);
 
Action<object> action2 = (objectParam) => { Console.WriteLine("Hello Action<object> {0}", objectParam.ToString()); };
Task.Factory.StartNew(action2, objectParam);
 
Func<string> func1 = () => { return "Hello Func"; };
Task.Factory.StartNew<string>(func1);
 
Func<object, string> func2 = (objectParam) => { return objectParam.ToString(); };
Task.Factory.StartNew<string>(func2, objectParam);


====================

Action action1 = () => { Console.WriteLine("Hello Action"); };
Task t1 = Task.Factory.StartNew(action1);
 
t1.Wait();
t1.ContinueWith(_t1 => { Console.WriteLine("t1 task end."); });
Task<string> retTask = t1.ContinueWith<string>((_t1) => { return "hi"; });
Console.WriteLine(retTask.Result);
HTML | PHP | C++ | DirectX11 | Javascript | C# | HTML5 | ASP | SQL | General | CSS | Oculus Rift | Unity3d | Virtools SDK | Tip | NSIS | PowerShell | node.js | Web API | RTSP | All
Copyright© 2016 CodeWee.com All rights reserved.