who will benefit from this talk topics what you’ll leave with asp.net developers, including web...

Post on 04-Jan-2016

217 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

www.buildwindows.com

Building IIS and ASP.NET apps with the power of async

Damian Edwards, Phil HaackProgram Managers, ASP.NETMicrosoft Corporation

SAC-804T

www.buildwindows.com

Agenda slide

WHO WILL BENEFIT FROM THIS TALK

TOPICS WHAT YOU’LL LEAVE WITH

• ASP.NET developers, including Web Forms & MVC

• History of async programming in .NET

• How async works in ASP.NET

• Using async in ASP.NET apps

• 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

www.buildwindows.com

Three async programming models

Asynchronous Programming

Model(APM)

Evented Asynchronous Programming

(EAP)

Task-based Asynchronous Programming

(TAP)

// .NET 1 model

file.BeginRead(buffer, 0, maxLength, asyncResult => {

int numBytesRead = file.EndRead(asyncResult); // Now do something with "buffer“

}, null);

Asynchronous Programming Model (APM)Asynchronous Programming Model (APM)

// .NET 2 model

webClient.DownloadStringCompleted += (sender, args) => {

string html = args.Result; // Now do something with "html"

};webClient.DownloadStringAsync(new Uri("http://example.com"));

Event-based Asynchronous Programming (EAP)

Task<string> htmlTask = webClient.DownloadStringTaskAsync(url);

htmlTask.ContinueWith(task => { string html = task.Result; // Async, C# 4});

string html = htmlTask.Result; // Sync (block until done)

string html = await htmlTask; // Async, C# 5

Task-based Asynchronous Programming (TAP)

public async Task<ViewResult> MyMethod(){ string myParam = "some value"; var data = await FetchSomeData(myParam); return View(data);} 2

1

public Task<ViewResult> MyMethod(){ string myParam = "some value"; return FetchSomeData(myParam).ContinueWith(task => { var data = task.Result; return View(data); });}

2

1

Before compilation

After compilation(conceptual)

How C# 5 “async” works

How async requests work in ASP.NET

www.buildwindows.com

Traditional Web request handling“thread-per-request” a.k.a. “post office”

Thread pool

Requests

BusyBusy Busy Busy

www.buildwindows.com

Asynchronous Web request handlinga.k.a. “restaurant”

Requests

Thread pool

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

So can I just use async everywhere in my ASP.NET app? No!

There are three (3) distinct scenarios where async in ASP.NET apps might be useful…

www.buildwindows.com

Async IO in ASP.NET

demo

www.buildwindows.com

Parallelizing work for faster request throughput

demo

www.buildwindows.com

Handling long running, event driven requests

demo

www.buildwindows.com

For more information

• TOOL-810T: Async made simple in Windows 8, with C# and Visual Basic

RELATED SESSIONS DOCUMENTATION & ARTICLES

• http://www.asp.net/vnext

www.buildwindows.com

• Feedback and questions http://forums.dev.windows.com

• Session feedbackhttp://bldw.in/SessionFeedback

thank you

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

top related