End Sub. 3. Build and run the application.
3. Build and run the application. 4. You should observe that this time all three Tasks completed before the final time was reported, indicating the end of the main thread. Figure 8 Output from running tasks in parallel with individual Wait() conditions
Note: The main thread waited for the created Task objects to complete before continuing operation. This approach is much simpler and cleaner than using ThreadPool.QueueUserWorkItem, which involves the creation and management of manual reset events, possible with the addition of Interlocked operations as well.
5. In addition to the Wait() method on the individual Task objects, the static Task class also offers a WaitAll() method allowing you to wait on a specified list of tasks with one call. To see this method in action, remove the individual calls to Wait() for task1, task2, and task3 and replace them with the following: C# static void Main(string[] args) { ... // Methods to call
|