SlideShare uma empresa Scribd logo
1 de 59
Author. Blogger. Speaker. C# MVP. Geek.
12:38
12:38
Load app
content
Sort
data
Process
records
Asynchronous task
UsingTasks
UsingAsyncandAwait
private async Task RunAsync()
{
var x = 10;
await Task.Delay(2000);
Debug.WriteLine(x);
}
private Task RunAsync()
{
<RunAsync>d__1 stateMachine = new <RunAsync>d__1 {
<>t__builder = AsyncTaskMethodBuilder.Create(),
<>1__state = -1
};
stateMachine.<>t__builder.Start<<RunAsync>d__1>(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
if (num != 0)
{
this.<x>5__1 = 10;
awaiter = Task.Delay(2000).GetAwaiter();
if (!awaiter.IsCompleted)
{
. . . . . . . . . . . .
return;
}
}
else
{
. . . . .
}
awaiter.GetResult();
awaiter = new TaskAwaiter();
Debug.WriteLine(this.<x>5__1);
private async void RunAsync()
{
var x = 10;
await Task.Delay(2000);
Debug.WriteLine(x);
}
private void RunAsync()
{
<RunAsync>d__1 stateMachine = new <RunAsync>d__1 {
<>t__builder = AsyncVoidMethodBuilder.Create(),
<>1__state = -1
};
stateMachine.<>t__builder.Start<<RunAsync>d__1>(ref stateMachine);
}
CloserlookatAsyncandAwait
AsyncandAwaitinASP.NET
$.post("ajax/test.html", function (data) {
$(".result").html(data);
})
Task.Run(() => { /* Lots of work to do! */ });
Task<string>.Run(() =>
{
/* Lots of work to do! */
return "Hello World!";
});
Task.Run(() => { /* Lots of work to do! */ })
.ContinueWith((t) => { Debug.WriteLine("Done!"); });
await Task.Run(() => { /* Lots of work to do! */ });
Debug.WriteLine("Done!");
Task.Run(() => "Hello World!")
.ContinueWith((task) => Debug.WriteLine(task.Result));
var result = await Task.Run(() => "Hello World!");
Debug.WriteLine(result);
private Task RunAsync()
{
<RunAsync>d__1 stateMachine = new <RunAsync>d__1 {
<>t__builder = AsyncTaskMethodBuilder.Create(),
<>1__state = -1
};
stateMachine.<>t__builder.Start<<RunAsync>d__1>(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
Task.Run(() => { /* Lots of work to do! */ })
.ContinueWith((t) => { Debug.WriteLine("Done!"); });
await Task.Run(() => { /* Lots of work to do! */ });
Debug.WriteLine("Done!");
if (num != 0)
{
this.<x>5__1 = 10;
awaiter = Task.Delay(2000).GetAwaiter();
if (!awaiter.IsCompleted)
{
. . . . . . . . . . . .
return;
}
}
else
{
. . . . .
}
awaiter.GetResult();
awaiter = new TaskAwaiter();
Debug.WriteLine(this.<x>5__1);
Task.Delay(1).ContinueWith((t) =>
{
Dispatcher.Invoke(() =>
{
});
}).Wait();
RunAsync().Wait();
Author. Blogger. Speaker. C# MVP. Geek.

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
Java I/O
Java I/OJava I/O
Java I/O
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
 
jQuery Ajax
jQuery AjaxjQuery Ajax
jQuery Ajax
 
ECMA Script
ECMA ScriptECMA Script
ECMA Script
 
Introduction to Facebook React
Introduction to Facebook ReactIntroduction to Facebook React
Introduction to Facebook React
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
 
Exception handling
Exception handlingException handling
Exception handling
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
React hooks
React hooksReact hooks
React hooks
 
Servlets
ServletsServlets
Servlets
 
React hooks
React hooksReact hooks
React hooks
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
JS Event Loop
JS Event LoopJS Event Loop
JS Event Loop
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
ESTEM_ReactJS_S1.pptx
ESTEM_ReactJS_S1.pptxESTEM_ReactJS_S1.pptx
ESTEM_ReactJS_S1.pptx
 
JDBC
JDBCJDBC
JDBC
 
7.data types in c#
7.data types in c#7.data types in c#
7.data types in c#
 

Semelhante a Asynchronous programming

オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
Takayuki Goto
 

Semelhante a Asynchronous programming (20)

No More Deadlocks; Asynchronous Programming in .NET
No More Deadlocks; Asynchronous Programming in .NETNo More Deadlocks; Asynchronous Programming in .NET
No More Deadlocks; Asynchronous Programming in .NET
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
 
Think Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJSThink Async: Asynchronous Patterns in NodeJS
Think Async: Asynchronous Patterns in NodeJS
 
Async Best Practices
Async Best PracticesAsync Best Practices
Async Best Practices
 
Asynchronní programování
Asynchronní programováníAsynchronní programování
Asynchronní programování
 
NodeJS: the good parts? A skeptic’s view (jax jax2013)
NodeJS: the good parts? A skeptic’s view (jax jax2013)NodeJS: the good parts? A skeptic’s view (jax jax2013)
NodeJS: the good parts? A skeptic’s view (jax jax2013)
 
16 18
16 1816 18
16 18
 
Automation in angular js
Automation in angular jsAutomation in angular js
Automation in angular js
 
Expert JavaScript tricks of the masters
Expert JavaScript  tricks of the mastersExpert JavaScript  tricks of the masters
Expert JavaScript tricks of the masters
 
Cnam azure 2014 mobile services
Cnam azure 2014   mobile servicesCnam azure 2014   mobile services
Cnam azure 2014 mobile services
 
Workshop: Async and Parallel in C#
Workshop: Async and Parallel in C#Workshop: Async and Parallel in C#
Workshop: Async and Parallel in C#
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)
 
Microsoft 2014 Dev Plataform - Roslyn -& ASP.NET vNext
Microsoft 2014 Dev Plataform -  Roslyn -& ASP.NET vNextMicrosoft 2014 Dev Plataform -  Roslyn -& ASP.NET vNext
Microsoft 2014 Dev Plataform - Roslyn -& ASP.NET vNext
 
Angular2 rxjs
Angular2 rxjsAngular2 rxjs
Angular2 rxjs
 
Reactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwiftReactive Programming Patterns with RxSwift
Reactive Programming Patterns with RxSwift
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
 
Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0Asynchronous web apps with the Play Framework 2.0
Asynchronous web apps with the Play Framework 2.0
 
Getting Started with Real-Time Analytics
Getting Started with Real-Time AnalyticsGetting Started with Real-Time Analytics
Getting Started with Real-Time Analytics
 
Apache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customizationApache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customization
 
Developing web-apps like it's 2013
Developing web-apps like it's 2013Developing web-apps like it's 2013
Developing web-apps like it's 2013
 

Mais de Filip Ekberg

Mais de Filip Ekberg (7)

C# 8 and Beyond
C# 8 and BeyondC# 8 and Beyond
C# 8 and Beyond
 
The State of C#
The State of C#The State of C#
The State of C#
 
Building APIs with MVC 6 and OAuth
Building APIs with MVC 6 and OAuthBuilding APIs with MVC 6 and OAuth
Building APIs with MVC 6 and OAuth
 
C# Is The Future
C# Is The FutureC# Is The Future
C# Is The Future
 
Asynchronous programming from Xamarin Hakcday in Melbourne
Asynchronous programming from Xamarin Hakcday in MelbourneAsynchronous programming from Xamarin Hakcday in Melbourne
Asynchronous programming from Xamarin Hakcday in Melbourne
 
Azure Mobile Services .NET Backend
Azure Mobile Services .NET BackendAzure Mobile Services .NET Backend
Azure Mobile Services .NET Backend
 
C# 6.0 - What?! C# is being updated?
C# 6.0 - What?! C# is being updated?C# 6.0 - What?! C# is being updated?
C# 6.0 - What?! C# is being updated?
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 

Asynchronous programming