SlideShare ist ein Scribd-Unternehmen logo
1 von 61
Downloaden Sie, um offline zu lesen
Asynchronous
Programming




    Learn More @ http://www.learnnowonline.com
       Copyright © by Application Developers Training Company
Asynchronous
Programming
           http://
   www.LearnNowOnline.com



     Learn More @ http://www.learnnowonline.com
        Copyright © by Application Developers Training Company
Understanding the Problem
with Previous Async




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Understanding the Problem
with Previous Async
• Demo




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Where Async Fits In




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Where Async Fits In
• Traditional code is synchronous




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Where Async Fits In
• Traditional code is synchronous
  • Call method, block until call returns,
   continue processing




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Where Async Fits In
• Traditional code is synchronous
  • Call method, block until call returns,
   continue processing
• Asynchronous (async) is non-blocking




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Where Async Fits In
• Traditional code is synchronous
  • Call method, block until call returns,
   continue processing
• Asynchronous (async) is non-blocking
  • Call, return immediately to continue
   processing, called method continues
   running



          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Where Async Fits In
• Traditional code is synchronous
  • Call method, block until call returns,
   continue processing
• Asynchronous (async) is non-blocking
  • Call, return immediately to continue
   processing, called method continues
   running
• UI is responsive and good use of server

          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Previous Async




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Previous Async
• Asynchronous Programming Model
  (APM)




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Previous Async
• Asynchronous Programming Model
  (APM)
  • Relies on delegates to handle execution
   and callback




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Previous Async
• Asynchronous Programming Model
  (APM)
  • Relies on delegates to handle execution
    and callback
  • Complex




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Previous Async
• Asynchronous Programming Model
  (APM)
  • Relies on delegates to handle execution
    and callback
  • Complex
• Event-based Asynchronous Pattern
  (EAP)


          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Previous Async
• Asynchronous Programming Model
  (APM)
  • Relies on delegates to handle execution
    and callback
  • Complex
• Event-based Asynchronous Pattern
  (EAP)
  • Simpler and more features than APM


          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Using the New async
and await Keywords




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Using the New async
and await Keywords
• Demo




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Anatomy of an Async




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Anatomy of an Async
• Modify method as async (required)




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Anatomy of an Async
• Modify method as async (required)
• Call method with await (optional)




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Anatomy of an Async
• Modify method as async (required)
• Call method with await (optional)
• Without await: generates compiler
  warning and method runs
  synchronously




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Anatomy of an Async
• Modify method as async (required)
• Call method with await (optional)
• Without await: generates compiler
  warning and method runs
  synchronously
• Method, lambda, or anonymous
  method


         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Anatomy of an Async
• Modify method as async (required)
• Call method with await (optional)
• Without await: generates compiler
  warning and method runs
  synchronously
• Method, lambda, or anonymous
  method
• Add Async suffix to method name
         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Async Return Values




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Async Return Values
• Can be void, Task, or Task<TResult>




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Async Return Values
• Can be void, Task, or Task<TResult>
• Use void for fire-and-forget




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Async Return Values
• Can be void, Task, or Task<TResult>
• Use void for fire-and-forget
  • Warning: can’t catch exception with void




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Async Return Values
• Can be void, Task, or Task<TResult>
• Use void for fire-and-forget
  • Warning: can’t catch exception with void
  • Appropriate for async event handlers




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Async Return Values
• Can be void, Task, or Task<TResult>
• Use void for fire-and-forget
  • Warning: can’t catch exception with void
  • Appropriate for async event handlers
• Task and Task<TResult> lets callers
  await your method




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Async Return Values
• Can be void, Task, or Task<TResult>
• Use void for fire-and-forget
  • Warning: can’t catch exception with void
  • Appropriate for async event handlers
• Task and Task<TResult> lets callers
  await your method
• Assign awaited value to variable and
  continue with rest of method

          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Managing Async Tasks




     Learn More @ http://www.learnnowonline.com
        Copyright © by Application Developers Training Company
Managing Async Tasks
• Demo




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
About Async Threads




     Learn More @ http://www.learnnowonline.com
        Copyright © by Application Developers Training Company
About Async Threads
• Call to await returns to caller on same
  thread




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
About Async Threads
• Call to await returns to caller on same
  thread
• Control automatically marshaled back
  to UI thread after await




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Awaiting in Sequence




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Awaiting in Sequence
• You can have as many awaits in a
  method that you want




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Awaiting in Sequence
• You can have as many awaits in a
  method that you want
• After one await completes, the next
  one executes




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Awaiting in Parallel




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Awaiting in Parallel
• You can await multiple methods
  together




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Awaiting in Parallel
• You can await multiple methods
  together
• Add all methods to
  List<Task<TResult>>




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Awaiting in Parallel
• You can await multiple methods
  together
• Add all methods to
  List<Task<TResult>>
• Call await on Task.WhenAll to process
  results after all tasks complete



         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Awaiting in Parallel
• You can await multiple methods
  together
• Add all methods to
  List<Task<TResult>>
• Call await on Task.WhenAll to process
  results after all tasks complete
• Call await on Task.WhenAny to process
  results for each result as it completes
         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Exceptions,
Cancellations, and




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Exceptions,
Cancellations, and
• Demo




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Handling Exceptions




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Handling Exceptions
• You can handle both synchronous and
  async code together




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Handling Exceptions
• You can handle both synchronous and
  async code together
• Use try/catch around await and it
  works




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Cancellation




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Cancellation
• Use CancellationTokenSource




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Cancellation
• Use CancellationTokenSource
• Pass Token to async methods




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Cancellation
• Use CancellationTokenSource
• Pass Token to async methods
• Wrap in try/catch for
  OperationCancelledException




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Cancellation
• Use CancellationTokenSource
• Pass Token to async methods
• Wrap in try/catch for
  OperationCancelledException
• Awaited code can check token for
  cancellation and throw



         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Progress Reporting




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Progress Reporting
• Modify async method to accept an
  IProgress<T>




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Progress Reporting
• Modify async method to accept an
  IProgress<T>
• Caller instantiates ProgressReport with
  callback




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Progress Reporting
• Modify async method to accept an
  IProgress<T>
• Caller instantiates ProgressReport with
  callback
• Caller passes the ProgressReport instance
  to the async method




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Progress Reporting
• Modify async method to accept an
  IProgress<T>
• Caller instantiates ProgressReport with
  callback
• Caller passes the ProgressReport instance
  to the async method
• The async method calls Report on
  IProgress<T> instance

          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Questions?




     Learn More @ http://www.learnnowonline.com
        Copyright © by Application Developers Training Company
Questions?

           http://
   www.LearnNowOnline.com



     Learn More @ http://www.learnnowonline.com
        Copyright © by Application Developers Training Company

Weitere ähnliche Inhalte

Was ist angesagt?

Chicago Tech Day Jan 2015: Foundry - HTTP2
Chicago Tech Day Jan 2015: Foundry - HTTP2Chicago Tech Day Jan 2015: Foundry - HTTP2
Chicago Tech Day Jan 2015: Foundry - HTTP2Akamai Technologies
 
Edge 2014: Million Browser Botnet - Live Demonstration
Edge 2014: Million Browser Botnet - Live DemonstrationEdge 2014: Million Browser Botnet - Live Demonstration
Edge 2014: Million Browser Botnet - Live DemonstrationAkamai Technologies
 
Rafaëla Breed - Tracing performance of your service calls - Codemotion Amster...
Rafaëla Breed - Tracing performance of your service calls - Codemotion Amster...Rafaëla Breed - Tracing performance of your service calls - Codemotion Amster...
Rafaëla Breed - Tracing performance of your service calls - Codemotion Amster...Codemotion
 
Frappé / ERPNext Open Day February 2016
Frappé / ERPNext Open Day February 2016Frappé / ERPNext Open Day February 2016
Frappé / ERPNext Open Day February 2016Anand Doshi
 
Chicago Tech Day Jan 2015: Hidden Features
Chicago Tech Day Jan 2015: Hidden FeaturesChicago Tech Day Jan 2015: Hidden Features
Chicago Tech Day Jan 2015: Hidden FeaturesAkamai Technologies
 
Edge 2014: Increasing Control with Property Manager with eBay
Edge 2014: Increasing Control with Property Manager with eBayEdge 2014: Increasing Control with Property Manager with eBay
Edge 2014: Increasing Control with Property Manager with eBayAkamai Technologies
 
ERPNext Open Day - March / April 2015
ERPNext Open Day - March / April 2015ERPNext Open Day - March / April 2015
ERPNext Open Day - March / April 2015rushabh_mehta
 
2015 Velocity SC: Convince your CFO that #perfmatters
2015 Velocity SC: Convince your CFO that #perfmatters2015 Velocity SC: Convince your CFO that #perfmatters
2015 Velocity SC: Convince your CFO that #perfmattersColin Bendell
 
Frappe / ERPNext Open Day May 14
Frappe / ERPNext Open Day May 14Frappe / ERPNext Open Day May 14
Frappe / ERPNext Open Day May 14rushabh_mehta
 
Resolution for a Faster Site
Resolution for a Faster SiteResolution for a Faster Site
Resolution for a Faster SiteIdo Safruti
 
QuizBrahma by Sagar Kadam
QuizBrahma by Sagar KadamQuizBrahma by Sagar Kadam
QuizBrahma by Sagar KadamSagar Kadam
 
Getting started with Visual Testing using Applitools - @TPC, Feb2020
Getting started with Visual Testing using Applitools - @TPC, Feb2020Getting started with Visual Testing using Applitools - @TPC, Feb2020
Getting started with Visual Testing using Applitools - @TPC, Feb2020Anand Bagmar
 
Lambdaless and AWS CDK
Lambdaless and AWS CDKLambdaless and AWS CDK
Lambdaless and AWS CDKMooYeol Lee
 
Yelowsoft delivers super app to bbr one of the biggest ride hailing companies...
Yelowsoft delivers super app to bbr one of the biggest ride hailing companies...Yelowsoft delivers super app to bbr one of the biggest ride hailing companies...
Yelowsoft delivers super app to bbr one of the biggest ride hailing companies...Yelowsoft
 
Yelowsoft delivers super app to bbr one of the biggest ride hailing companies...
Yelowsoft delivers super app to bbr one of the biggest ride hailing companies...Yelowsoft delivers super app to bbr one of the biggest ride hailing companies...
Yelowsoft delivers super app to bbr one of the biggest ride hailing companies...Yelowsoft
 
Automated Acceptance Test Practices and Pitfalls
Automated Acceptance Test Practices and PitfallsAutomated Acceptance Test Practices and Pitfalls
Automated Acceptance Test Practices and PitfallsWyn B. Van Devanter
 

Was ist angesagt? (18)

Chicago Tech Day Jan 2015: Foundry - HTTP2
Chicago Tech Day Jan 2015: Foundry - HTTP2Chicago Tech Day Jan 2015: Foundry - HTTP2
Chicago Tech Day Jan 2015: Foundry - HTTP2
 
Edge 2014: Million Browser Botnet - Live Demonstration
Edge 2014: Million Browser Botnet - Live DemonstrationEdge 2014: Million Browser Botnet - Live Demonstration
Edge 2014: Million Browser Botnet - Live Demonstration
 
Rafaëla Breed - Tracing performance of your service calls - Codemotion Amster...
Rafaëla Breed - Tracing performance of your service calls - Codemotion Amster...Rafaëla Breed - Tracing performance of your service calls - Codemotion Amster...
Rafaëla Breed - Tracing performance of your service calls - Codemotion Amster...
 
Frappé / ERPNext Open Day February 2016
Frappé / ERPNext Open Day February 2016Frappé / ERPNext Open Day February 2016
Frappé / ERPNext Open Day February 2016
 
Chicago Tech Day Jan 2015: Hidden Features
Chicago Tech Day Jan 2015: Hidden FeaturesChicago Tech Day Jan 2015: Hidden Features
Chicago Tech Day Jan 2015: Hidden Features
 
Edge 2014: Increasing Control with Property Manager with eBay
Edge 2014: Increasing Control with Property Manager with eBayEdge 2014: Increasing Control with Property Manager with eBay
Edge 2014: Increasing Control with Property Manager with eBay
 
ERPNext Open Day - March / April 2015
ERPNext Open Day - March / April 2015ERPNext Open Day - March / April 2015
ERPNext Open Day - March / April 2015
 
Startup Pitching and Mobile App Startup
Startup Pitching and Mobile App StartupStartup Pitching and Mobile App Startup
Startup Pitching and Mobile App Startup
 
2015 Velocity SC: Convince your CFO that #perfmatters
2015 Velocity SC: Convince your CFO that #perfmatters2015 Velocity SC: Convince your CFO that #perfmatters
2015 Velocity SC: Convince your CFO that #perfmatters
 
SFScon18 - Juri Strumpflohner - End-to-end testing done right!
SFScon18 - Juri Strumpflohner - End-to-end testing done right!SFScon18 - Juri Strumpflohner - End-to-end testing done right!
SFScon18 - Juri Strumpflohner - End-to-end testing done right!
 
Frappe / ERPNext Open Day May 14
Frappe / ERPNext Open Day May 14Frappe / ERPNext Open Day May 14
Frappe / ERPNext Open Day May 14
 
Resolution for a Faster Site
Resolution for a Faster SiteResolution for a Faster Site
Resolution for a Faster Site
 
QuizBrahma by Sagar Kadam
QuizBrahma by Sagar KadamQuizBrahma by Sagar Kadam
QuizBrahma by Sagar Kadam
 
Getting started with Visual Testing using Applitools - @TPC, Feb2020
Getting started with Visual Testing using Applitools - @TPC, Feb2020Getting started with Visual Testing using Applitools - @TPC, Feb2020
Getting started with Visual Testing using Applitools - @TPC, Feb2020
 
Lambdaless and AWS CDK
Lambdaless and AWS CDKLambdaless and AWS CDK
Lambdaless and AWS CDK
 
Yelowsoft delivers super app to bbr one of the biggest ride hailing companies...
Yelowsoft delivers super app to bbr one of the biggest ride hailing companies...Yelowsoft delivers super app to bbr one of the biggest ride hailing companies...
Yelowsoft delivers super app to bbr one of the biggest ride hailing companies...
 
Yelowsoft delivers super app to bbr one of the biggest ride hailing companies...
Yelowsoft delivers super app to bbr one of the biggest ride hailing companies...Yelowsoft delivers super app to bbr one of the biggest ride hailing companies...
Yelowsoft delivers super app to bbr one of the biggest ride hailing companies...
 
Automated Acceptance Test Practices and Pitfalls
Automated Acceptance Test Practices and PitfallsAutomated Acceptance Test Practices and Pitfalls
Automated Acceptance Test Practices and Pitfalls
 

Andere mochten auch

WPF: Working with Data
WPF: Working with DataWPF: Working with Data
WPF: Working with DataLearnNowOnline
 
Windows 8: Shapes and Geometries
Windows 8: Shapes and GeometriesWindows 8: Shapes and Geometries
Windows 8: Shapes and GeometriesLearnNowOnline
 
New in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDENew in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDELearnNowOnline
 
SQL: Permissions and Data Protection
SQL: Permissions and Data ProtectionSQL: Permissions and Data Protection
SQL: Permissions and Data ProtectionLearnNowOnline
 
Attributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingAttributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingLearnNowOnline
 

Andere mochten auch (6)

WPF: Working with Data
WPF: Working with DataWPF: Working with Data
WPF: Working with Data
 
Windows 8: Shapes and Geometries
Windows 8: Shapes and GeometriesWindows 8: Shapes and Geometries
Windows 8: Shapes and Geometries
 
New in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDENew in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDE
 
WPF Binding
WPF BindingWPF Binding
WPF Binding
 
SQL: Permissions and Data Protection
SQL: Permissions and Data ProtectionSQL: Permissions and Data Protection
SQL: Permissions and Data Protection
 
Attributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingAttributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programming
 

Ähnlich wie Asynchronous Programming

JavaScript: Operators and Expressions
JavaScript: Operators and ExpressionsJavaScript: Operators and Expressions
JavaScript: Operators and ExpressionsLearnNowOnline
 
.NET Variables and Data Types
.NET Variables and Data Types.NET Variables and Data Types
.NET Variables and Data TypesLearnNowOnline
 
Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5LearnNowOnline
 
Using The .NET Framework
Using The .NET FrameworkUsing The .NET Framework
Using The .NET FrameworkLearnNowOnline
 
Creating a User Interface
Creating a User InterfaceCreating a User Interface
Creating a User InterfaceLearnNowOnline
 
Working with Controllers and Actions in MVC
Working with Controllers and Actions in MVCWorking with Controllers and Actions in MVC
Working with Controllers and Actions in MVCLearnNowOnline
 
KnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVCKnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVCLearnNowOnline
 
What's new in Silverlight 5
What's new in Silverlight 5What's new in Silverlight 5
What's new in Silverlight 5LearnNowOnline
 
.Net branching and flow control
.Net branching and flow control.Net branching and flow control
.Net branching and flow controlLearnNowOnline
 
Managing site collections
Managing site collectionsManaging site collections
Managing site collectionsLearnNowOnline
 
Bring a Web Page Alive with jQuery
Bring a Web Page Alive with jQueryBring a Web Page Alive with jQuery
Bring a Web Page Alive with jQueryLearnNowOnline
 
Object oriented techniques
Object oriented techniquesObject oriented techniques
Object oriented techniquesLearnNowOnline
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScriptLearnNowOnline
 
Flink Forward Berlin 2018: Wei-Che (Tony) Wei - "Lessons learned from Migrati...
Flink Forward Berlin 2018: Wei-Che (Tony) Wei - "Lessons learned from Migrati...Flink Forward Berlin 2018: Wei-Che (Tony) Wei - "Lessons learned from Migrati...
Flink Forward Berlin 2018: Wei-Che (Tony) Wei - "Lessons learned from Migrati...Flink Forward
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCLearnNowOnline
 

Ähnlich wie Asynchronous Programming (20)

JavaScript: Operators and Expressions
JavaScript: Operators and ExpressionsJavaScript: Operators and Expressions
JavaScript: Operators and Expressions
 
Web API Basics
Web API BasicsWeb API Basics
Web API Basics
 
.NET Variables and Data Types
.NET Variables and Data Types.NET Variables and Data Types
.NET Variables and Data Types
 
Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5
 
Using The .NET Framework
Using The .NET FrameworkUsing The .NET Framework
Using The .NET Framework
 
Creating a User Interface
Creating a User InterfaceCreating a User Interface
Creating a User Interface
 
SQL Server: Security
SQL Server: SecuritySQL Server: Security
SQL Server: Security
 
Working with Controllers and Actions in MVC
Working with Controllers and Actions in MVCWorking with Controllers and Actions in MVC
Working with Controllers and Actions in MVC
 
KnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVCKnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVC
 
What's new in Silverlight 5
What's new in Silverlight 5What's new in Silverlight 5
What's new in Silverlight 5
 
.Net branching and flow control
.Net branching and flow control.Net branching and flow control
.Net branching and flow control
 
Managing site collections
Managing site collectionsManaging site collections
Managing site collections
 
Generics
GenericsGenerics
Generics
 
Bring a Web Page Alive with jQuery
Bring a Web Page Alive with jQueryBring a Web Page Alive with jQuery
Bring a Web Page Alive with jQuery
 
Object oriented techniques
Object oriented techniquesObject oriented techniques
Object oriented techniques
 
Introducing LINQ
Introducing LINQIntroducing LINQ
Introducing LINQ
 
The Entity Data Model
The Entity Data ModelThe Entity Data Model
The Entity Data Model
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScript
 
Flink Forward Berlin 2018: Wei-Che (Tony) Wei - "Lessons learned from Migrati...
Flink Forward Berlin 2018: Wei-Che (Tony) Wei - "Lessons learned from Migrati...Flink Forward Berlin 2018: Wei-Che (Tony) Wei - "Lessons learned from Migrati...
Flink Forward Berlin 2018: Wei-Che (Tony) Wei - "Lessons learned from Migrati...
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 

Mehr von LearnNowOnline

SharePoint Document Management
SharePoint Document ManagementSharePoint Document Management
SharePoint Document ManagementLearnNowOnline
 
SharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPathSharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPathLearnNowOnline
 
Sql 2012 development and programming
Sql 2012  development and programmingSql 2012  development and programming
Sql 2012 development and programmingLearnNowOnline
 
Expression Blend Motion & Interaction Design
Expression Blend Motion & Interaction DesignExpression Blend Motion & Interaction Design
Expression Blend Motion & Interaction DesignLearnNowOnline
 
Introducing the Entity Framework
Introducing the Entity FrameworkIntroducing the Entity Framework
Introducing the Entity FrameworkLearnNowOnline
 

Mehr von LearnNowOnline (6)

A tour of SQL Server
A tour of SQL ServerA tour of SQL Server
A tour of SQL Server
 
SharePoint Document Management
SharePoint Document ManagementSharePoint Document Management
SharePoint Document Management
 
SharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPathSharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPath
 
Sql 2012 development and programming
Sql 2012  development and programmingSql 2012  development and programming
Sql 2012 development and programming
 
Expression Blend Motion & Interaction Design
Expression Blend Motion & Interaction DesignExpression Blend Motion & Interaction Design
Expression Blend Motion & Interaction Design
 
Introducing the Entity Framework
Introducing the Entity FrameworkIntroducing the Entity Framework
Introducing the Entity Framework
 

Asynchronous Programming

  • 1. Asynchronous Programming Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 2. Asynchronous Programming http:// www.LearnNowOnline.com Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 3. Understanding the Problem with Previous Async Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 4. Understanding the Problem with Previous Async • Demo Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 5. Where Async Fits In Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 6. Where Async Fits In • Traditional code is synchronous Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 7. Where Async Fits In • Traditional code is synchronous • Call method, block until call returns, continue processing Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 8. Where Async Fits In • Traditional code is synchronous • Call method, block until call returns, continue processing • Asynchronous (async) is non-blocking Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 9. Where Async Fits In • Traditional code is synchronous • Call method, block until call returns, continue processing • Asynchronous (async) is non-blocking • Call, return immediately to continue processing, called method continues running Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 10. Where Async Fits In • Traditional code is synchronous • Call method, block until call returns, continue processing • Asynchronous (async) is non-blocking • Call, return immediately to continue processing, called method continues running • UI is responsive and good use of server Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 11. Previous Async Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 12. Previous Async • Asynchronous Programming Model (APM) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 13. Previous Async • Asynchronous Programming Model (APM) • Relies on delegates to handle execution and callback Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 14. Previous Async • Asynchronous Programming Model (APM) • Relies on delegates to handle execution and callback • Complex Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 15. Previous Async • Asynchronous Programming Model (APM) • Relies on delegates to handle execution and callback • Complex • Event-based Asynchronous Pattern (EAP) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 16. Previous Async • Asynchronous Programming Model (APM) • Relies on delegates to handle execution and callback • Complex • Event-based Asynchronous Pattern (EAP) • Simpler and more features than APM Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 17. Using the New async and await Keywords Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 18. Using the New async and await Keywords • Demo Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 19. Anatomy of an Async Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 20. Anatomy of an Async • Modify method as async (required) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 21. Anatomy of an Async • Modify method as async (required) • Call method with await (optional) Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 22. Anatomy of an Async • Modify method as async (required) • Call method with await (optional) • Without await: generates compiler warning and method runs synchronously Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 23. Anatomy of an Async • Modify method as async (required) • Call method with await (optional) • Without await: generates compiler warning and method runs synchronously • Method, lambda, or anonymous method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 24. Anatomy of an Async • Modify method as async (required) • Call method with await (optional) • Without await: generates compiler warning and method runs synchronously • Method, lambda, or anonymous method • Add Async suffix to method name Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 25. Async Return Values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 26. Async Return Values • Can be void, Task, or Task<TResult> Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 27. Async Return Values • Can be void, Task, or Task<TResult> • Use void for fire-and-forget Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 28. Async Return Values • Can be void, Task, or Task<TResult> • Use void for fire-and-forget • Warning: can’t catch exception with void Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 29. Async Return Values • Can be void, Task, or Task<TResult> • Use void for fire-and-forget • Warning: can’t catch exception with void • Appropriate for async event handlers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 30. Async Return Values • Can be void, Task, or Task<TResult> • Use void for fire-and-forget • Warning: can’t catch exception with void • Appropriate for async event handlers • Task and Task<TResult> lets callers await your method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 31. Async Return Values • Can be void, Task, or Task<TResult> • Use void for fire-and-forget • Warning: can’t catch exception with void • Appropriate for async event handlers • Task and Task<TResult> lets callers await your method • Assign awaited value to variable and continue with rest of method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 32. Managing Async Tasks Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 33. Managing Async Tasks • Demo Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 34. About Async Threads Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 35. About Async Threads • Call to await returns to caller on same thread Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 36. About Async Threads • Call to await returns to caller on same thread • Control automatically marshaled back to UI thread after await Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 37. Awaiting in Sequence Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 38. Awaiting in Sequence • You can have as many awaits in a method that you want Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 39. Awaiting in Sequence • You can have as many awaits in a method that you want • After one await completes, the next one executes Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 40. Awaiting in Parallel Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 41. Awaiting in Parallel • You can await multiple methods together Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 42. Awaiting in Parallel • You can await multiple methods together • Add all methods to List<Task<TResult>> Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 43. Awaiting in Parallel • You can await multiple methods together • Add all methods to List<Task<TResult>> • Call await on Task.WhenAll to process results after all tasks complete Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 44. Awaiting in Parallel • You can await multiple methods together • Add all methods to List<Task<TResult>> • Call await on Task.WhenAll to process results after all tasks complete • Call await on Task.WhenAny to process results for each result as it completes Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 45. Exceptions, Cancellations, and Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 46. Exceptions, Cancellations, and • Demo Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 47. Handling Exceptions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 48. Handling Exceptions • You can handle both synchronous and async code together Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 49. Handling Exceptions • You can handle both synchronous and async code together • Use try/catch around await and it works Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 50. Cancellation Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 51. Cancellation • Use CancellationTokenSource Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 52. Cancellation • Use CancellationTokenSource • Pass Token to async methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 53. Cancellation • Use CancellationTokenSource • Pass Token to async methods • Wrap in try/catch for OperationCancelledException Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 54. Cancellation • Use CancellationTokenSource • Pass Token to async methods • Wrap in try/catch for OperationCancelledException • Awaited code can check token for cancellation and throw Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 55. Progress Reporting Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 56. Progress Reporting • Modify async method to accept an IProgress<T> Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 57. Progress Reporting • Modify async method to accept an IProgress<T> • Caller instantiates ProgressReport with callback Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 58. Progress Reporting • Modify async method to accept an IProgress<T> • Caller instantiates ProgressReport with callback • Caller passes the ProgressReport instance to the async method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 59. Progress Reporting • Modify async method to accept an IProgress<T> • Caller instantiates ProgressReport with callback • Caller passes the ProgressReport instance to the async method • The async method calls Report on IProgress<T> instance Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 60. Questions? Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 61. Questions? http:// www.LearnNowOnline.com Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n