WHO WILL BENEFIT FROM THIS TALK ASP NET


WHO WILL BENEFIT FROM THIS TALK • ASP. NET developers, including Web Forms & MVC TOPICS • • • History of async programming in. NET How async works in ASP. NET Using async in ASP. NET apps WHAT YOU’LL LEAVE WITH • • • How to use async programming in ASP. NET to increase scalability, improve page response time and implement long running requests The Task Parallel Library (TPL) and async/await support in in C# and. NET 4. 5 makes programming async much easier than traditional APM ASP. NET 4. 5, including the core framework, Web Forms and MVC, has great support for working with the TPL and async/await

A brief history of async programming in. NET

Asynchronous Programming Model (APM) Evented Asynchronous Programming (EAP) Task-based Asynchronous Programming (TAP)

Asynchronous Programming Model (APM) //. NET 1 model file. Begin. Read(buffer, 0, max. Length, async. Result => { int num. Bytes. Read = file. End. Read(async. Result); // Now do something with "buffer“ }, null);

//. NET 2 model web. Client. Download. String. Completed += (sender, args) => { string html = args. Result; // Now do something with "html" }; web. Client. Download. String. Async(new Uri("http: //example. com"));

Task<string> html. Task = web. Client. Download. String. Task. Async(url); string html = html. Task. Result; // Sync (block until done) html. Task. Continue. With(task => { string html = task. Result; // Async, C# 4 }); string html = await html. Task; // Async, C# 5

Before compilation public async Task<View. Result> My. Method() { string my. Param = "some value"; 1 var data = await Fetch. Some. Data(my. Param); return View(data); 2 } After compilation (conceptual) public Task<View. Result> My. Method() { string my. Param = "some value"; 1 return Fetch. Some. Data(my. Param). Continue. With(task => { var data = task. Result; return View(data); 2 }); }

How async requests work in ASP. NET

Traditional Web request handling “thread-per-request” a. k. a. “post office” Requests Thread pool Busy

Asynchronous Web request handling a. k. a. “restaurant” Requests Thread pool

Using async for benefit in ASP. NET apps. Easy as 1, 3, 2






RELATED SESSIONS DOCUMENTATION & ARTICLES • TOOL-810 T: Async made simple in Windows 8, with C# and Visual Basic • http: //www. asp. net/vnext

http: //forums. dev. windows. com http: //bldw. in/Session. Feedback


- Slides: 21