O'Reilly logo

C++ Multithreading Cookbook by Milos Ljumovic

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required