Task is a powerful tool for Microsoft's new asynchronous programming in the. NET Framework 4.0, of course 4.5 new async, await, here we first say task-related.
In the actual programming, we use more is Task, Task.Factory.StarNew, Task.run, next simple expression under my understanding.
// incoming func delegate task<intnew task<intreturn (int11); Task . Start (); Console.WriteLine (Task. Result); // Incoming Action Delegate New Task (() = Console.WriteLine ("a")); Task1. Start ();
The instantiated task object needs to call start to start the task, and if you use Task.Factory.StarNew, you do not have to call the Start method to start the task.
var task = task.factory.startnew<intreturn1;}); Console.WriteLine (Task. Result); var task1 = Task.Factory.StartNew (() = Console.WriteLine (" this is StartNew ... "));
Task.run is not much different from Task.Factory.StarNew and new task, the difference is that the first two are put into the thread pool for immediate execution, while Task.run is executing when the thread pool is idle.
The Run method accepts only the non-parameter action and Func delegates, and the other two accept an argument of type object.
TaskFactory in MSDN. StartNew's note information is as follows:
They can either call the Wait method to block the current thread, or they can get the return value through Task.result, which, of course, blocks the current thread.
Then say the usual continuewith, this is a continuation of the execution of a task, similar to callback
var task = task.factory.startnew<intreturn1;}); Console.WriteLine (Task. Result); var result = task. continuewith<intreturn1;})); Console.WriteLine (Result. Result);
ContinueWith accepts an action or Func delegate, the first parameter of the delegate is a task type, which allows access to the previous Task object
Novice talking about C#task asynchronous programming