SlideShare une entreprise Scribd logo
1  sur  17
DEVintersection
Session AS12
Building Asynchronous ASP.NET Applications
2
© DEVintersection. All rights reserved.
http://www.DEVintersection.com
Agenda
 Quick History
 When is Async Useful
 Parallelism
 Tips & Resources
3
© DEVintersection. All rights reserved.
http://www.DEVintersection.com
Async in .NET
.NET Framework 1.0 / 1.1
 1.0 – no async available
 1.1 – APM: Async Programming Model
IAsyncResult result = StartProcess(..);
// continue doing other work
// checking result.IsCompleted
int final = EndProcess(result);
4
© DEVintersection. All rights reserved.
http://www.DEVintersection.com
Async in .NET
.NET Framework 2.0
 EAP: Event-base Async Pattern
ProcessCompleted += (sender, e) =>
{
// process the result here
};
AsyncProcessStart(…);
5
© DEVintersection. All rights reserved.
http://www.DEVintersection.com
Async in .NET
.NET Framework 4.0
 TPL: Task Parallel Library

Task<int> t = ProcessAsync(…);
// process other work
// check t.Status, t.IsFaulted, etc.
int result = t.Result;
6
© DEVintersection. All rights reserved.
http://www.DEVintersection.com
Async in .NET
.NET Framework 4.5
 async/await keywords
public async Task<int> Process() {
int result = await CompleteWork();
return result;
}
7
© DEVintersection. All rights reserved.
http://www.DEVintersection.com
When to Async
When is it most useful?
 I/O


 Parallelism
 Long Running Tasks
8
© DEVintersection. All rights reserved.
http://www.DEVintersection.com
Application Architecture
50 States
Web API
Web Forms
Application
Warnings db
Demo
WebForms
10
© DEVintersection. All rights reserved.
http://www.DEVintersection.com
WebForms
Notes
 DO NOT async your Page_Load
 RegisterAsyncTask
 Set Async=“true” on your .aspx page to enable async pipeline
Demo
MVC / Web API
12
© DEVintersection. All rights reserved.
http://www.DEVintersection.com
MVC / Web API
Notes
 Simple & Transparent
 Mark method as async, return Task<T>
 Use Entity Framework >= 6.1 for async methods


13
© DEVintersection. All rights reserved.
http://www.DEVintersection.com
Parallelism
 Task.WhenAll
 Task.Run, ThreadPool.QueueUserWorkItem

Demo
Parallelism
15
© DEVintersection. All rights reserved.
http://www.DEVintersection.com
Final Comments
 Avoid using Background Threads
 Do not use Task.Wait()

 Avoid Using Task.ContinueWith

 Parallel != Async

16
© DEVintersection. All rights reserved.
http://www.DEVintersection.com
Resource & Links
 Hanselminutes Podcast – Everything .NET programmers know about
Asynchronous Programming is wrong.
http://hanselminutes.com/327/everything-net-programmers-know-
about-asynchronous-programming-is-wrong
 Using Asynchronous Methods in ASP.NET 4.5
http://www.asp.net/web-forms/tutorials/aspnet-45/using-asynchronous-
methods-in-aspnet-45
 Contact Information

Questions?
Thank you!
Don’t forget to enter your evaluation
of this session using EventBoard!

Contenu connexe

En vedette (16)

Sun
SunSun
Sun
 
Bài 5
Bài 5Bài 5
Bài 5
 
Jeff king iditarod 2014
Jeff king iditarod 2014Jeff king iditarod 2014
Jeff king iditarod 2014
 
Pols presentation
Pols presentation Pols presentation
Pols presentation
 
Croazia turismo
Croazia turismoCroazia turismo
Croazia turismo
 
rahul recent
rahul recentrahul recent
rahul recent
 
Grading visible learners nagel-slides visible learning institute san diego
Grading visible learners nagel-slides visible learning institute san diegoGrading visible learners nagel-slides visible learning institute san diego
Grading visible learners nagel-slides visible learning institute san diego
 
Competition presentation
Competition presentationCompetition presentation
Competition presentation
 
English project
English projectEnglish project
English project
 
Trabajo marta y ana (inglés)
Trabajo marta y ana (inglés)Trabajo marta y ana (inglés)
Trabajo marta y ana (inglés)
 
My food diary Marco 5a
My food diary Marco 5aMy food diary Marco 5a
My food diary Marco 5a
 
Tarea 1. corrección
Tarea 1. correcciónTarea 1. corrección
Tarea 1. corrección
 
My favorite sports alejandro 5b si blog
My favorite sports alejandro 5b si blogMy favorite sports alejandro 5b si blog
My favorite sports alejandro 5b si blog
 
Toscana turismo
Toscana turismoToscana turismo
Toscana turismo
 
創業管理:兼職創業者完整課程 week7
創業管理:兼職創業者完整課程 week7創業管理:兼職創業者完整課程 week7
創業管理:兼職創業者完整課程 week7
 
創業管理:兼職創業者完整課程 Week 5
創業管理:兼職創業者完整課程 Week 5創業管理:兼職創業者完整課程 Week 5
創業管理:兼職創業者完整課程 Week 5
 

Similaire à Async ASP.NET Applications

Async in .NET
Async in .NETAsync in .NET
Async in .NET
RTigger
 
End to-end async and await
End to-end async and awaitEnd to-end async and await
End to-end async and await
vfabro
 
ApacheCon NA 2010 - Building Apps with Apache Tuscany
ApacheCon NA 2010 - Building Apps with Apache TuscanyApacheCon NA 2010 - Building Apps with Apache Tuscany
ApacheCon NA 2010 - Building Apps with Apache Tuscany
Jean-Sebastien Delfino
 
.Net Multithreading and Parallelization
.Net Multithreading and Parallelization.Net Multithreading and Parallelization
.Net Multithreading and Parallelization
Dmitri Nesteruk
 

Similaire à Async ASP.NET Applications (20)

Training – Going Async
Training – Going AsyncTraining – Going Async
Training – Going Async
 
Async and Await on the Server
Async and Await on the ServerAsync and Await on the Server
Async and Await on the Server
 
Workshop: Async and Parallel in C#
Workshop: Async and Parallel in C#Workshop: Async and Parallel in C#
Workshop: Async and Parallel in C#
 
Async in .NET
Async in .NETAsync in .NET
Async in .NET
 
Webcast: Asynchronous Programming Demystified
Webcast: Asynchronous Programming DemystifiedWebcast: Asynchronous Programming Demystified
Webcast: Asynchronous Programming Demystified
 
End to-end async and await
End to-end async and awaitEnd to-end async and await
End to-end async and await
 
Asp.net tips
Asp.net tipsAsp.net tips
Asp.net tips
 
Async Programming in C# 5
Async Programming in C# 5Async Programming in C# 5
Async Programming in C# 5
 
Task parallel library presentation
Task parallel library presentationTask parallel library presentation
Task parallel library presentation
 
Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0Binary Studio Academy: Concurrency in C# 5.0
Binary Studio Academy: Concurrency in C# 5.0
 
Spring Actionscript at Devoxx
Spring Actionscript at DevoxxSpring Actionscript at Devoxx
Spring Actionscript at Devoxx
 
Liberating web apps from the server
Liberating web apps from the serverLiberating web apps from the server
Liberating web apps from the server
 
Apache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's NextApache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's Next
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!NGINX Can Do That? Test Drive Your Config File!
NGINX Can Do That? Test Drive Your Config File!
 
Concurrecny inf sharp
Concurrecny inf sharpConcurrecny inf sharp
Concurrecny inf sharp
 
ApacheCon NA 2010 - Building Apps with Apache Tuscany
ApacheCon NA 2010 - Building Apps with Apache TuscanyApacheCon NA 2010 - Building Apps with Apache Tuscany
ApacheCon NA 2010 - Building Apps with Apache Tuscany
 
Asynchronous Programming.pptx
Asynchronous Programming.pptxAsynchronous Programming.pptx
Asynchronous Programming.pptx
 
.Net Multithreading and Parallelization
.Net Multithreading and Parallelization.Net Multithreading and Parallelization
.Net Multithreading and Parallelization
 
Ddd melbourne 2011 C# async ctp
Ddd melbourne 2011  C# async ctpDdd melbourne 2011  C# async ctp
Ddd melbourne 2011 C# async ctp
 

Dernier

CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Dernier (20)

Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

Async ASP.NET Applications

  • 2. 2 © DEVintersection. All rights reserved. http://www.DEVintersection.com Agenda  Quick History  When is Async Useful  Parallelism  Tips & Resources
  • 3. 3 © DEVintersection. All rights reserved. http://www.DEVintersection.com Async in .NET .NET Framework 1.0 / 1.1  1.0 – no async available  1.1 – APM: Async Programming Model IAsyncResult result = StartProcess(..); // continue doing other work // checking result.IsCompleted int final = EndProcess(result);
  • 4. 4 © DEVintersection. All rights reserved. http://www.DEVintersection.com Async in .NET .NET Framework 2.0  EAP: Event-base Async Pattern ProcessCompleted += (sender, e) => { // process the result here }; AsyncProcessStart(…);
  • 5. 5 © DEVintersection. All rights reserved. http://www.DEVintersection.com Async in .NET .NET Framework 4.0  TPL: Task Parallel Library  Task<int> t = ProcessAsync(…); // process other work // check t.Status, t.IsFaulted, etc. int result = t.Result;
  • 6. 6 © DEVintersection. All rights reserved. http://www.DEVintersection.com Async in .NET .NET Framework 4.5  async/await keywords public async Task<int> Process() { int result = await CompleteWork(); return result; }
  • 7. 7 © DEVintersection. All rights reserved. http://www.DEVintersection.com When to Async When is it most useful?  I/O    Parallelism  Long Running Tasks
  • 8. 8 © DEVintersection. All rights reserved. http://www.DEVintersection.com Application Architecture 50 States Web API Web Forms Application Warnings db
  • 10. 10 © DEVintersection. All rights reserved. http://www.DEVintersection.com WebForms Notes  DO NOT async your Page_Load  RegisterAsyncTask  Set Async=“true” on your .aspx page to enable async pipeline
  • 12. 12 © DEVintersection. All rights reserved. http://www.DEVintersection.com MVC / Web API Notes  Simple & Transparent  Mark method as async, return Task<T>  Use Entity Framework >= 6.1 for async methods  
  • 13. 13 © DEVintersection. All rights reserved. http://www.DEVintersection.com Parallelism  Task.WhenAll  Task.Run, ThreadPool.QueueUserWorkItem 
  • 15. 15 © DEVintersection. All rights reserved. http://www.DEVintersection.com Final Comments  Avoid using Background Threads  Do not use Task.Wait()   Avoid Using Task.ContinueWith   Parallel != Async 
  • 16. 16 © DEVintersection. All rights reserved. http://www.DEVintersection.com Resource & Links  Hanselminutes Podcast – Everything .NET programmers know about Asynchronous Programming is wrong. http://hanselminutes.com/327/everything-net-programmers-know- about-asynchronous-programming-is-wrong  Using Asynchronous Methods in ASP.NET 4.5 http://www.asp.net/web-forms/tutorials/aspnet-45/using-asynchronous- methods-in-aspnet-45  Contact Information 
  • 17. Questions? Thank you! Don’t forget to enter your evaluation of this session using EventBoard!