1.Wait Usage
By default, a task is executed by an asynchronous thread in a wired pool, whether it is done or not, and can be judged by the property iscompleted of the task.
If you want to work on a child thread after the work is done, the subsequent main thread can be worked on by calling task. Wait () waits for the thread to finish, and after the wait is called, the current thread is blocked until the child thread finishes.
code example:
static void Main (string[] args) { Task t = Task.run (() = { thread.sleep (); Console.WriteLine ("Lance"); Thread.Sleep (+); }); Console.WriteLine ("t.iscompleted=" + t.iscompleted); T.wait (); Console.WriteLine ("t.iscompleted=" + t.iscompleted); }
Operation Result:
2.Wait Set Wait Time
static void Main (string[] args) { Task t = Task.run (() = { thread.sleep (); Console.WriteLine ("Lance"); Thread.Sleep (+); }); Console.WriteLine ("t.iscompleted=" + t.iscompleted); BOOL iscomplate= t.wait (+); Console.WriteLine ("Wait 200 milliseconds after t.iscompleted=" + t.iscompleted); Thread.Sleep (+); Console.WriteLine ("t.iscompleted=" + t.iscompleted); }
Operation Result: