SlideShare a Scribd company logo
1 of 27
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
Correcting common mistakes, async await
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
async Task ReadDataFromUrl(string url)
{
WebClient wc = new WebClient();
byte[] result = await wc.DownloadDataTaskAsync(url);
string data = Encoding.ASCII.GetString(result);
LoadData(data);
}
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
async Task ReadDataFromUrl(string url)
{
WebClient wc = new WebClient();
byte[] result = await wc.DownloadDataTaskAsync(url);
string data = Encoding.ASCII.GetString(result);
LoadData(data);
}
Thread 1
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
async Task ReadDataFromUrl(string url)
{
WebClient wc = new WebClient();
byte[] result = await wc.DownloadDataTaskAsync(url);
string data = Encoding.ASCII.GetString(result);
LoadData(data);
}
Thread 2
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
async Task ReadDataFromUrl(string url)
{
WebClient wc = new WebClient();
byte[] result = await wc.DownloadDataTaskAsync(url);
string data = Encoding.ASCII.GetString(result);
LoadData(data);
}
Thread 1
Correcting common mistakes, async await
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
async Task ReadDataFromUrl(string url)
{
WebClient wc = new WebClient();
byte[] result = await wc.DownloadDataTaskAsync(url);
string data = Encoding.ASCII.GetString(result);
LoadData(data);
}
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
async Task ReadDataFromUrl(string url)
{
WebClient wc = new WebClient();
byte[] result = await wc.DownloadDataTaskAsync(url);
string data = Encoding.ASCII.GetString(result);
LoadData(data);
}
private sealed class <ReadDataFromUrl>d_1 : IAsyncStateMachine
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
async Task ReadDataFromUrl(string url)
{
WebClient wc = new WebClient();
byte[] result = await wc.DownloadDataTaskAsync(url);
string data = Encoding.ASCII.GetString(result);
LoadData(data);
}
private string <data>5_3;
private byte[] <result>5_2;
private WebClient <wc>5_1;
public string url;
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
async Task ReadDataFromUrl(string url)
{
WebClient wc = new WebClient();
byte[] result = await wc.DownloadDataTaskAsync(url);
string data = Encoding.ASCII.GetString(result);
LoadData(data);
}
private void MoveNext();
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
public void MoveNext()
{
uint num = (uint)this.$PC;
this.$PC = -1;
try {
switch (num) {
case 0:
this.<wc>__0 = new WebClient();
this.$awaiter0 = this.<wc>__0.DownloadDataTaskAsync(this.url).GetAwaiter();
this.$PC = 1;
...
return;
break;
case 1:
this.<result>__1 = this.$awaiter0.GetResult();
this.<data>__2 = Encoding.ASCII.GetString(this.<result>__1);
this.$this.LoadData(this.<data>__2);
break;
default:
return;
}
}
catch (Exception exception) { ... }
this.$PC = -1;
this.$builder.SetResult();
}
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
public void MoveNext()
{
uint num = (uint)this.$PC;
this.$PC = -1;
try {
switch (num) {
case 0:
this.<wc>__0 = new WebClient();
this.$awaiter0 = this.<wc>__0.DownloadDataTaskAsync(this.url).GetAwaiter();
this.$PC = 1;
...
return;
break;
case 1:
this.<result>__1 = this.$awaiter0.GetResult();
this.<data>__2 = Encoding.ASCII.GetString(this.<result>__1);
this.$this.LoadData(this.<data>__2);
break;
default:
return;
}
}
catch (Exception exception) { ... }
this.$PC = -1;
this.$builder.SetResult();
}
case 0:
this.<wc>__0 = new WebClient();
this.$awaiter0 = this.<wc>__0.DownloadDataTaskAsync(this.url).GetAwaiter();
this.$PC = 1;
...
return;
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
public void MoveNext()
{
uint num = (uint)this.$PC;
this.$PC = -1;
try {
switch (num) {
case 0:
this.<wc>__0 = new WebClient();
this.$awaiter0 = this.<wc>__0.DownloadDataTaskAsync(this.url).GetAwaiter();
this.$PC = 1;
...
return;
break;
case 1:
this.<result>__1 = this.$awaiter0.GetResult();
this.<data>__2 = Encoding.ASCII.GetString(this.<result>__1);
this.$this.LoadData(this.<data>__2);
break;
default:
return;
}
}
catch (Exception exception) { ... }
this.$PC = -1;
this.$builder.SetResult();
}
case 1:
this.<result>__1 = this.$awaiter0.GetResult();
this.<data>__2 = Encoding.ASCII.GetString(this.<result>__1);
this.$this.LoadData(this.<data>__2);
break;
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
public void MoveNext()
{
uint num = (uint)this.$PC;
this.$PC = -1;
try {
switch (num) {
case 0:
this.<wc>__0 = new WebClient();
this.$awaiter0 = this.<wc>__0.DownloadDataTaskAsync(this.url).GetAwaiter();
this.$PC = 1;
...
return;
break;
case 1:
this.<result>__1 = this.$awaiter0.GetResult();
this.<data>__2 = Encoding.ASCII.GetString(this.<result>__1);
this.$this.LoadData(this.<data>__2);
break;
default:
return;
}
}
catch (Exception exception) { ... }
this.$PC = -1;
this.$builder.SetResult();
}
try {
catch (Exception exception) { . . . }
Correcting common mistakes, async await
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
Correcting common mistakes, async await
Correcting common mistakes, async await
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait
@TheCodeTraveler https://www.codetraveler.io/NDCSydney-2018-AsyncAwait

More Related Content

More from Brandon Minnick, MBA

Introduction to Serverless with AWS Lambda in C#.pptx
Introduction to Serverless with AWS Lambda in C#.pptxIntroduction to Serverless with AWS Lambda in C#.pptx
Introduction to Serverless with AWS Lambda in C#.pptxBrandon Minnick, MBA
 
Correcting Common .NET Mistakes in Async Await .pptx
Correcting Common .NET Mistakes in Async Await .pptxCorrecting Common .NET Mistakes in Async Await .pptx
Correcting Common .NET Mistakes in Async Await .pptxBrandon Minnick, MBA
 
Introducing .NET MAUI Toolkit.pptx
Introducing .NET MAUI Toolkit.pptxIntroducing .NET MAUI Toolkit.pptx
Introducing .NET MAUI Toolkit.pptxBrandon Minnick, MBA
 
Creating Apps With .NET MAUI for iOS, Android, macOS + Windows
Creating AppsWith .NET MAUIfor iOS, Android, macOS + WindowsCreating AppsWith .NET MAUIfor iOS, Android, macOS + Windows
Creating Apps With .NET MAUI for iOS, Android, macOS + WindowsBrandon Minnick, MBA
 
Creating iOS & Android Apps using Xamarin
Creating iOS & Android Apps using XamarinCreating iOS & Android Apps using Xamarin
Creating iOS & Android Apps using XamarinBrandon Minnick, MBA
 
Creating Native iOS & Android Apps in C#
Creating Native iOS & Android Apps in C#Creating Native iOS & Android Apps in C#
Creating Native iOS & Android Apps in C#Brandon Minnick, MBA
 
DevReach: Creating Xamarin.Forms UIs in C#
DevReach: Creating Xamarin.Forms UIs in C#DevReach: Creating Xamarin.Forms UIs in C#
DevReach: Creating Xamarin.Forms UIs in C#Brandon Minnick, MBA
 
Creating Serverless Apps without Writing Any Code
Creating Serverless Apps without Writing Any CodeCreating Serverless Apps without Writing Any Code
Creating Serverless Apps without Writing Any CodeBrandon Minnick, MBA
 

More from Brandon Minnick, MBA (20)

Creating Apps with .NET MAUI.pptx
Creating Apps with .NET MAUI.pptxCreating Apps with .NET MAUI.pptx
Creating Apps with .NET MAUI.pptx
 
Building GraphQL APIs in C#.pptx
Building GraphQL APIs in C#.pptxBuilding GraphQL APIs in C#.pptx
Building GraphQL APIs in C#.pptx
 
Introduction to Serverless with AWS Lambda in C#.pptx
Introduction to Serverless with AWS Lambda in C#.pptxIntroduction to Serverless with AWS Lambda in C#.pptx
Introduction to Serverless with AWS Lambda in C#.pptx
 
Consuming GraphQL APIs in C#.pptx
Consuming GraphQL APIs in C#.pptxConsuming GraphQL APIs in C#.pptx
Consuming GraphQL APIs in C#.pptx
 
Correcting Common .NET Mistakes in Async Await .pptx
Correcting Common .NET Mistakes in Async Await .pptxCorrecting Common .NET Mistakes in Async Await .pptx
Correcting Common .NET Mistakes in Async Await .pptx
 
Building GraphQL API in C#.pptx
Building GraphQL API in C#.pptxBuilding GraphQL API in C#.pptx
Building GraphQL API in C#.pptx
 
Introducing .NET MAUI Toolkit.pptx
Introducing .NET MAUI Toolkit.pptxIntroducing .NET MAUI Toolkit.pptx
Introducing .NET MAUI Toolkit.pptx
 
Building MAUI UI in C#.pptx
Building MAUI UI in C#.pptxBuilding MAUI UI in C#.pptx
Building MAUI UI in C#.pptx
 
Building GraphQL API in C#.pptx
Building GraphQL API in C#.pptxBuilding GraphQL API in C#.pptx
Building GraphQL API in C#.pptx
 
Creating Apps with .NET MAUI
Creating Apps with .NET MAUICreating Apps with .NET MAUI
Creating Apps with .NET MAUI
 
Creating Apps With .NET MAUI for iOS, Android, macOS + Windows
Creating AppsWith .NET MAUIfor iOS, Android, macOS + WindowsCreating AppsWith .NET MAUIfor iOS, Android, macOS + Windows
Creating Apps With .NET MAUI for iOS, Android, macOS + Windows
 
Creating Xamarin.Forms UIs is C#
Creating Xamarin.Forms UIs is C#Creating Xamarin.Forms UIs is C#
Creating Xamarin.Forms UIs is C#
 
The Future of Xamarin
The Future of XamarinThe Future of Xamarin
The Future of Xamarin
 
Creating iOS & Android Apps using Xamarin
Creating iOS & Android Apps using XamarinCreating iOS & Android Apps using Xamarin
Creating iOS & Android Apps using Xamarin
 
Xamarin + GraphQL
Xamarin + GraphQLXamarin + GraphQL
Xamarin + GraphQL
 
Creating Native iOS & Android Apps in C#
Creating Native iOS & Android Apps in C#Creating Native iOS & Android Apps in C#
Creating Native iOS & Android Apps in C#
 
DevReach: Creating Xamarin.Forms UIs in C#
DevReach: Creating Xamarin.Forms UIs in C#DevReach: Creating Xamarin.Forms UIs in C#
DevReach: Creating Xamarin.Forms UIs in C#
 
The Future of Xamarin
The Future of XamarinThe Future of Xamarin
The Future of Xamarin
 
Creating Serverless Apps without Writing Any Code
Creating Serverless Apps without Writing Any CodeCreating Serverless Apps without Writing Any Code
Creating Serverless Apps without Writing Any Code
 
The Future of Xamarin
The Future of XamarinThe Future of Xamarin
The Future of Xamarin
 

Recently uploaded

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Recently uploaded (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Correcting common mistakes, async await

Editor's Notes

  1. Every time we add the `async` keyword, the compiler creates a new class. Each class increases our app size by appx. 100 bytes
  2. Every time we add the `async` keyword, the compiler creates a new class. Each class increases our app size by appx. 100 bytes
  3. Every time we add the `async` keyword, the compiler creates a new class. Each class increases our app size by appx. 100 bytes
  4. Best way to learn – free videos Paid for instructors Certification, actually valued by employers Great ecosystem of books