Event-based Asynchronous Pattern

Microsoft .NET provides Event-based Asynchronous Pattern (EAP), which offers multithreading capability without the need for a programmer to explicitly create or start a thread or task. Such classes are BackgroundWorker or WebClient. We'll focus on BackgroundWorker later in detail. Now, we'll simply point out the features of WebClient and will expand our factorial example to use an event instead of posting messages.

The managed WebClient class, among others, provides methods for downloading data in synchronous and asynchronous execution. Our interest is in asynchronous methods. The code follows

[HostProtectionAttribute(SecurityAction::LinkDemand, ExternalThreading = true)] public: void DownloadDataAsync( Uri^ address ...

Get C++ Multithreading Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.