210 likes | 417 Views
SAC-804T. Building IIS and ASP.NET apps with the power of async. Damian Edwards, Phil Haack Program Managers, ASP.NET Microsoft Corporation. Agenda slide. WHO WILL BENEFIT FROM THIS TALK. TOPICS. WHAT YOU’LL LEAVE WITH.
E N D
SAC-804T Building IIS and ASP.NET apps with the power of async Damian Edwards, Phil Haack Program Managers, ASP.NET Microsoft Corporation
Agenda slide WHO WILL BENEFIT FROM THIS TALK TOPICS WHAT YOU’LL LEAVE WITH • How to use asyncprogramming 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 • History of async programming in .NET • How async works in ASP.NET • Using async in ASP.NET apps • ASP.NET developers, including Web Forms & MVC
Three async programming models Asynchronous Programming Model (APM) Evented Asynchronous Programming (EAP) Task-based Asynchronous Programming (TAP)
Asynchronous Programming Model (APM) Asynchronous Programming Model (APM) // .NET 1 model file.BeginRead(buffer, 0, maxLength, asyncResult => { intnumBytesRead = file.EndRead(asyncResult); // Now do something with "buffer“ }, null);
Event-based Asynchronous Programming (EAP) // .NET 2 model webClient.DownloadStringCompleted += (sender, args) => { string html = args.Result; // Now do something with "html" }; webClient.DownloadStringAsync(newUri("http://example.com"));
Task-based Asynchronous Programming (TAP) Task<string> htmlTask= webClient.DownloadStringTaskAsync(url); string html = htmlTask.Result; // Sync (block until done) htmlTask.ContinueWith(task => { string html = task.Result; // Async, C# 4 }); string html = awaithtmlTask; // Async, C# 5
How C# 5 “async” works publicasyncTask<ViewResult> MyMethod() { stringmyParam = "some value"; var data = awaitFetchSomeData(myParam); return View(data); } Before compilation 1 2 After compilation (conceptual) publicTask<ViewResult> MyMethod() { stringmyParam = "some value"; return FetchSomeData(myParam).ContinueWith(task => { vardata = task.Result; return View(data); }); } 1 2
Traditional Web request handling “thread-per-request” a.k.a. “post office” Requests Thread pool Busy Busy Busy Busy
Asynchronous Web request handling a.k.a. “restaurant” Requests Thread pool
There are three (3) distinct scenarios where async in ASP.NET apps might be useful…
demo Async IO in ASP.NET
demo Parallelizing work for faster request throughput
demo Handling long running, event driven requests
For more information RELATED SESSIONS DOCUMENTATION & ARTICLES http://www.asp.net/vnext TOOL-810T: Async made simple in Windows 8, with C# and Visual Basic
thank you Feedback and questions http://forums.dev.windows.com Session feedbackhttp://bldw.in/SessionFeedback
© 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.