Asynchronous Programming

Most of the time, developers write code that processes a series of commands sequentially. For instance, we can envision a simple routine (TallyExpenseReport) that accepts an ID, calls a second routine (GetExpenseReport) to call a service with that ID to retrieve an expense report, grabs the total dollar amount of the expense report, and then updates a database before finally giving the user a message indicating the status of the operation.

C#

public void TallyExpenseReport(string id){    //get the expense report    ExpenseReport rpt = GetExpenseReport(id);    UpdateDataStore(id, rpt.TotalAmt);}public ExpenseReport GetExpenseReport(string id){    //code to fetch an expense report goes here ...

Get Microsoft Visual Studio 2015 Unleashed, Third Edition 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.