Switching Threads
In Chapter 40 you learned how to write code that can run on a separate thread, how to create new threads manually, and how to use the Thread Pool managed by the .NET Framework. With this approach, you run a portion of synchronous code in a separate thread, thus keeping the caller thread-free from an intensive and potentially blocking work. In the .NET Framework 4.6, you have additional alternatives to reach the same objective but writing simpler code. The Task.Run
method enables you to run a new task asynchronously, queuing such a task into a thread in the Thread Pool. The result is returned as Task
handle for the intensive work, so that you can use Await
to wait for the result. Task.Run
takes as the first argument a delegate ...
Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.