Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in...

15
Fast, Faster... Async ASP.NET Tiberiu Covaci Level: Intermediate

Transcript of Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in...

Page 1: Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in Azure/ASP.NET Geek @tibor19 Agenda ASP.NET Page lifecycle Load test your application Asynchronous

Fast, Faster... Async ASP.NETTiberiu Covaci

Level: Intermediate

Page 2: Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in Azure/ASP.NET Geek @tibor19 Agenda ASP.NET Page lifecycle Load test your application Asynchronous

Who am I?

Tiberiu ’Tibi’ Covaci

Software engineer, 25 years experience

CTO for Learning Connexions

MCT since 2004, teaching .NET

Telerik MVP & Insider

MVP in Azure/ASP.NET

Geek

@tibor19

Page 3: Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in Azure/ASP.NET Geek @tibor19 Agenda ASP.NET Page lifecycle Load test your application Asynchronous

Agenda

ASP.NET Page lifecycle

Load test your application

Asynchronous pages

Asynchronous actions

Async support in C# vNext

Page 4: Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in Azure/ASP.NET Geek @tibor19 Agenda ASP.NET Page lifecycle Load test your application Asynchronous

ASP.NET Page lifecycle

Init

Load

PreRender

PreRender

Complete

Page 5: Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in Azure/ASP.NET Geek @tibor19 Agenda ASP.NET Page lifecycle Load test your application Asynchronous

DEMO

Introducing the Application.

Page 6: Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in Azure/ASP.NET Geek @tibor19 Agenda ASP.NET Page lifecycle Load test your application Asynchronous

Sync vs Ansync

Synchronous

Call method => Wait for result

One method at a time

Easy to program/understand

Asynchronous

Call method => Return right away

Result / method completion provided via callback

Run several methods at the same time

Scalability

Harder to program

Page 7: Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in Azure/ASP.NET Geek @tibor19 Agenda ASP.NET Page lifecycle Load test your application Asynchronous

EventHandler Delegate

• void Invoke(object sender, EventArgs e)

• IAsyncResult BeginInvoke(

object sender,

EventArgs e,

AsyncCallback cb,

object state)• void EndInvoke(IAsyncResult ar)

Page 8: Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in Azure/ASP.NET Geek @tibor19 Agenda ASP.NET Page lifecycle Load test your application Asynchronous

ASP.NET Async Page lifecycle

Init

Load

PreRender

PreRender

Complete

Async calls

Page 9: Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in Azure/ASP.NET Geek @tibor19 Agenda ASP.NET Page lifecycle Load test your application Asynchronous

DEMO

Asynchronizing the

Application.

Page 10: Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in Azure/ASP.NET Geek @tibor19 Agenda ASP.NET Page lifecycle Load test your application Asynchronous

Async support in C# vNext

• “Looks like” synchronous programming

• Uses Task/Task<T> behind the courtains

• Two new contextual keywords

async marks a method as asynchrnous

await yields control while waiting on a task to complete

Page 11: Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in Azure/ASP.NET Geek @tibor19 Agenda ASP.NET Page lifecycle Load test your application Asynchronous

APM=>Async

public static Task<SqlDataReader> ExecuteReaderAsync(SqlCommand cmd)

{

var tcs = new TaskCompletionSource<SqlDataReader>();

cmd.BeginExecuteReader(iar =>

{

try

{

tcs.TrySetResult(cmd.EndExecuteReader(iar));

}

catch (Exception exc)

{

tcs.TrySetException(exc);

}

}, null);

return tcs.Task;

}

Page 12: Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in Azure/ASP.NET Geek @tibor19 Agenda ASP.NET Page lifecycle Load test your application Asynchronous

DEMO

Modernizing the

Application.

Page 13: Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in Azure/ASP.NET Geek @tibor19 Agenda ASP.NET Page lifecycle Load test your application Asynchronous

Summary

ASP.NET Page lifecycle

Load test your application

Asynchronous pages

Asynchronous actions

Async support in C# vNext

Page 14: Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in Azure/ASP.NET Geek @tibor19 Agenda ASP.NET Page lifecycle Load test your application Asynchronous

Q & A

Page 15: Fast, Faster Async ASPsddconf.com/brands/sdd/library/Fast_Faster_Async_ASP.NET.pdfMVP in Azure/ASP.NET Geek @tibor19 Agenda ASP.NET Page lifecycle Load test your application Asynchronous

Thank-you!

• Please fill out the evaluation!

• Contact me by

Email [email protected]

Twitter tibor19

And Don’t Forget to Write!