SlideShare a Scribd company logo
1 of 15
Asynchronous in DotNet4.5
[object Object],[object Object]
Task & Task<T> ,[object Object],[object Object],http://msdn.microsoft.com/en-us/library/system.threading.tasks.task(v=VS.110).aspx
Action<object> action = (object obj) => { Console.WriteLine(&quot;Task={0}, obj={1}, Thread={2}&quot;, Task.CurrentId, obj.ToString(), Thread.CurrentThread.ManagedThreadId); }; // Construct an unstarted task Task t1 = new Task(action, &quot;alpha&quot;); // Cosntruct a started task Task t2 = Task.Factory.StartNew(action, &quot;beta&quot;); // Block the main thread to demonstate that t2 is executing t2.Wait(); // Launch t1  t1.Start(); Console.WriteLine(&quot;t1 has been launched. (Main Thread={0})&quot;, Thread.CurrentThread.ManagedThreadId); // Wait for the task to finish. You may optionally provide a timeout interval or a cancellation token to mitigate situations when the task takes too long to finish. t1.Wait(); // Construct an unstarted task Task t3 = new Task(action, &quot;gamma&quot;); // Run it synchronously t3.RunSynchronously(); // Although the task was run synchrounously, it is a good practice to wait for it which observes for  // exceptions potentially thrown by that task. t3.Wait();
async await ,[object Object],[object Object],[object Object],[object Object],http://msdn.microsoft.com/en-us/library/hh156513(v=VS.110).aspx
public  async   Task<int>  ExampleMethodAsync() { // . . . // At the await expression, execution in this method is suspended and, // if AwaitedProcessAsync has not already finished, control returns // to the caller of ExampleMethodAsync. int exampleInt =  await  AwaitedProcessAsync(); // . . . // The return statement completes the task. Any method that is  // awaiting ExampleMethodAsync can now get the integer result. return exampleInt; }
// An event handler must return void. private  async  void button1_Click(object sender, RoutedEventArgs e) { textBox1.Clear(); // SumPageSizesAsync returns a Task. await SumPageSizesAsync(); textBox1.Text += &quot;Control returned to button1_Click.&quot;; } // The following async lambda expression creates an equivalent anonymous // event handler. button1.Click +=  async  (sender, e) => { textBox1.Clear(); // SumPageSizesAsync returns a Task. await  SumPageSizesAsync(); textBox1.Text += &quot;Control returned to button1_Click.&quot;; }
// The following async method returns a Task<T>. private  async  Task<byte[]> GetByteArrayAsync(Uri currentURI) { // Declare an HttpClient object.  HttpClient client = new HttpClient(); // The GetAsync method returns a Task(Of T), where T is an HttpResponseMessage. Task<HttpResponseMessage> httpRMTask = client.GetAsync(currentURI); // Await httpRMTask evaluates to an HttpResponseMessage object. HttpResponseMessage httpRM =  await  httpRMTask; // The following line can replace the previous two assignment statements . //HttpResponseMessage httpRM =  await  client.GetAsync(currentURI); // Throw an exception if the HttpResponseMessage contains an error code. httpRM.EnsureSuccessStatusCode(); // Use ReadAsByteArray to access the content of the resource as a byte array. return httpRM.Content.ReadAsByteArray(); }
Task Parallelism http://msdn.microsoft.com/en-us/library/dd537609(v=VS.110).aspx   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],http://msdn.microsoft.com/en-us/library/hh191443(v=VS.110).aspx
Async Samples ,[object Object]
[object Object]
public void AsyncIntroSerialBefore() { var client = new WebClient(); client.DownloadStringCompleted += AsyncIntroSerialBefore_DownloadStringCompleted_1; client.DownloadStringAsync(new Uri(&quot;http://www.weather.gov&quot;)); } void AsyncIntroSerialBefore_DownloadStringCompleted_1(object sender, DownloadStringCompletedEventArgs e) { WriteLinePageTitle(e.Result); var client = new WebClient(); client.DownloadStringCompleted += AsyncIntroSerialBefore_DownloadStringCompleted_2; client.DownloadStringAsync(new Uri(&quot;http://www.weather.gov/climate/&quot;)); } void AsyncIntroSerialBefore_DownloadStringCompleted_2(object sender, DownloadStringCompletedEventArgs e) { WriteLinePageTitle(e.Result); var client = new WebClient(); client.DownloadStringCompleted += AsyncIntroSerialBefore_DownloadStringCompleted_3; client.DownloadStringAsync(new Uri(&quot;http://www.weather.gov/rss/&quot;)); } void AsyncIntroSerialBefore_DownloadStringCompleted_3(object sender, DownloadStringCompletedEventArgs e) { WriteLinePageTitle(e.Result); } C# 4.0
public async void AsyncIntroSerial() { var client = new WebClient(); WriteLinePageTitle(await client.DownloadStringTaskAsync(new Uri(&quot;http://www.weather.gov&quot;))); WriteLinePageTitle(await client.DownloadStringTaskAsync(new Uri(&quot;http://www.weather.gov/climate/&quot;))); WriteLinePageTitle(await client.DownloadStringTaskAsync(new Uri(&quot;http://www.weather.gov/rss/&quot;))); } Async
Resources http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-829T

More Related Content

What's hot

OTP application (with gen server child) - simple example
OTP application (with gen server child) - simple exampleOTP application (with gen server child) - simple example
OTP application (with gen server child) - simple exampleYangJerng Hwa
 
Debugging over tcp and http
Debugging over tcp and httpDebugging over tcp and http
Debugging over tcp and httpKaniska Mandal
 
Testing logging in asp dot net core
Testing logging in asp dot net coreTesting logging in asp dot net core
Testing logging in asp dot net coreRajesh Shirsagar
 
692015 programming assignment 1 building a multi­threaded w
692015 programming assignment 1 building a multi­threaded w692015 programming assignment 1 building a multi­threaded w
692015 programming assignment 1 building a multi­threaded wsmile790243
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)aeden_brines
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and loopingChaAstillas
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.gerrell
 
Firefox Easily Analyzed by PVS-Studio Standalone
Firefox Easily Analyzed by PVS-Studio StandaloneFirefox Easily Analyzed by PVS-Studio Standalone
Firefox Easily Analyzed by PVS-Studio StandaloneAndrey Karpov
 
PVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckPVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckAndrey Karpov
 
Angular 4 The new Http Client Module
Angular 4 The new Http Client ModuleAngular 4 The new Http Client Module
Angular 4 The new Http Client Modulearjun singh
 
Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping newaprilyyy
 

What's hot (19)

OTP application (with gen server child) - simple example
OTP application (with gen server child) - simple exampleOTP application (with gen server child) - simple example
OTP application (with gen server child) - simple example
 
Debugging over tcp and http
Debugging over tcp and httpDebugging over tcp and http
Debugging over tcp and http
 
Tdd iPhone For Dummies
Tdd iPhone For DummiesTdd iPhone For Dummies
Tdd iPhone For Dummies
 
Testing logging in asp dot net core
Testing logging in asp dot net coreTesting logging in asp dot net core
Testing logging in asp dot net core
 
692015 programming assignment 1 building a multi­threaded w
692015 programming assignment 1 building a multi­threaded w692015 programming assignment 1 building a multi­threaded w
692015 programming assignment 1 building a multi­threaded w
 
Async await
Async awaitAsync await
Async await
 
Closures
ClosuresClosures
Closures
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
Lecture5
Lecture5Lecture5
Lecture5
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.
 
Firefox Easily Analyzed by PVS-Studio Standalone
Firefox Easily Analyzed by PVS-Studio StandaloneFirefox Easily Analyzed by PVS-Studio Standalone
Firefox Easily Analyzed by PVS-Studio Standalone
 
PVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckPVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd Check
 
Call Back
Call BackCall Back
Call Back
 
Call Back
Call BackCall Back
Call Back
 
C++ Functions
C++ FunctionsC++ Functions
C++ Functions
 
Oop object oriented programing topics
Oop object oriented programing topicsOop object oriented programing topics
Oop object oriented programing topics
 
Angular 4 The new Http Client Module
Angular 4 The new Http Client ModuleAngular 4 The new Http Client Module
Angular 4 The new Http Client Module
 
Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping new
 

Viewers also liked

Blogs in the Classroom
Blogs in the ClassroomBlogs in the Classroom
Blogs in the ClassroomAlisa Cooper
 
Python with dot net and vs2010
Python with dot net and vs2010Python with dot net and vs2010
Python with dot net and vs2010Wei Sun
 
Connect Composition Student Registration Information
Connect Composition Student Registration InformationConnect Composition Student Registration Information
Connect Composition Student Registration InformationAlisa Cooper
 
Registering for Connect Writing (ENG091)
Registering for Connect Writing (ENG091)Registering for Connect Writing (ENG091)
Registering for Connect Writing (ENG091)Alisa Cooper
 
Visual studio 11 developer preview
Visual studio 11 developer previewVisual studio 11 developer preview
Visual studio 11 developer previewWei Sun
 
Using google appengine
Using google appengineUsing google appengine
Using google appengineWei Sun
 
Using google appengine_final2
Using google appengine_final2Using google appengine_final2
Using google appengine_final2Wei Sun
 
Using google appengine_1027
Using google appengine_1027Using google appengine_1027
Using google appengine_1027Wei Sun
 
Promoting the Use of Social Media in Education
Promoting the Use of Social Media in Education Promoting the Use of Social Media in Education
Promoting the Use of Social Media in Education Alisa Cooper
 
Student Presentation: To Kill a Mockingbird
Student Presentation: To Kill a MockingbirdStudent Presentation: To Kill a Mockingbird
Student Presentation: To Kill a MockingbirdAlisa Cooper
 

Viewers also liked (12)

Blogs in the Classroom
Blogs in the ClassroomBlogs in the Classroom
Blogs in the Classroom
 
Python with dot net and vs2010
Python with dot net and vs2010Python with dot net and vs2010
Python with dot net and vs2010
 
Sensei kukikan
Sensei kukikanSensei kukikan
Sensei kukikan
 
Connect Composition Student Registration Information
Connect Composition Student Registration InformationConnect Composition Student Registration Information
Connect Composition Student Registration Information
 
Registering for Connect Writing (ENG091)
Registering for Connect Writing (ENG091)Registering for Connect Writing (ENG091)
Registering for Connect Writing (ENG091)
 
Visual studio 11 developer preview
Visual studio 11 developer previewVisual studio 11 developer preview
Visual studio 11 developer preview
 
Using google appengine
Using google appengineUsing google appengine
Using google appengine
 
Using google appengine_final2
Using google appengine_final2Using google appengine_final2
Using google appengine_final2
 
Using google appengine_1027
Using google appengine_1027Using google appengine_1027
Using google appengine_1027
 
Unit 1 abg izhar
Unit 1 abg izharUnit 1 abg izhar
Unit 1 abg izhar
 
Promoting the Use of Social Media in Education
Promoting the Use of Social Media in Education Promoting the Use of Social Media in Education
Promoting the Use of Social Media in Education
 
Student Presentation: To Kill a Mockingbird
Student Presentation: To Kill a MockingbirdStudent Presentation: To Kill a Mockingbird
Student Presentation: To Kill a Mockingbird
 

Similar to Asynchronous in dot net4

Sync with async
Sync with  asyncSync with  async
Sync with asyncprabathsl
 
Windows Phone 8 - 3.5 Async Programming
Windows Phone 8 - 3.5 Async ProgrammingWindows Phone 8 - 3.5 Async Programming
Windows Phone 8 - 3.5 Async ProgrammingOliver Scheer
 
Conociendo el consumo de datos en Windows Phone 8.1
Conociendo el consumo de datos en Windows Phone 8.1Conociendo el consumo de datos en Windows Phone 8.1
Conociendo el consumo de datos en Windows Phone 8.1Cristian González
 
Ddd melbourne 2011 C# async ctp
Ddd melbourne 2011  C# async ctpDdd melbourne 2011  C# async ctp
Ddd melbourne 2011 C# async ctpPratik Khasnabis
 
Understanding ASP.NET Under The Cover - Miguel A. Castro
Understanding ASP.NET Under The Cover - Miguel A. CastroUnderstanding ASP.NET Under The Cover - Miguel A. Castro
Understanding ASP.NET Under The Cover - Miguel A. CastroMohammad Tayseer
 
Android development training programme , Day 3
Android development training programme , Day 3Android development training programme , Day 3
Android development training programme , Day 3DHIRAJ PRAVIN
 
동기화 시대를 뛰어넘는 비동기 프로그래밍
동기화 시대를 뛰어넘는 비동기 프로그래밍동기화 시대를 뛰어넘는 비동기 프로그래밍
동기화 시대를 뛰어넘는 비동기 프로그래밍명신 김
 
Session 9 Android Web Services - Part 2.pdf
Session 9 Android Web Services - Part 2.pdfSession 9 Android Web Services - Part 2.pdf
Session 9 Android Web Services - Part 2.pdfEngmohammedAlzared
 
Asynchronous reading and writing http r equest
Asynchronous reading and writing http r equestAsynchronous reading and writing http r equest
Asynchronous reading and writing http r equestPragyanshis Patnaik
 
Concurrency - responsiveness in .NET
Concurrency - responsiveness in .NETConcurrency - responsiveness in .NET
Concurrency - responsiveness in .NETMårten Rånge
 
Implementing Comet using PHP
Implementing Comet using PHPImplementing Comet using PHP
Implementing Comet using PHPKing Foo
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2wiradikusuma
 
Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)Yoshifumi Kawai
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpointwebhostingguy
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestPavan Chitumalla
 

Similar to Asynchronous in dot net4 (20)

Sync with async
Sync with  asyncSync with  async
Sync with async
 
Async Programming in C# 5
Async Programming in C# 5Async Programming in C# 5
Async Programming in C# 5
 
Windows Phone 8 - 3.5 Async Programming
Windows Phone 8 - 3.5 Async ProgrammingWindows Phone 8 - 3.5 Async Programming
Windows Phone 8 - 3.5 Async Programming
 
Conociendo el consumo de datos en Windows Phone 8.1
Conociendo el consumo de datos en Windows Phone 8.1Conociendo el consumo de datos en Windows Phone 8.1
Conociendo el consumo de datos en Windows Phone 8.1
 
Ddd melbourne 2011 C# async ctp
Ddd melbourne 2011  C# async ctpDdd melbourne 2011  C# async ctp
Ddd melbourne 2011 C# async ctp
 
Understanding ASP.NET Under The Cover - Miguel A. Castro
Understanding ASP.NET Under The Cover - Miguel A. CastroUnderstanding ASP.NET Under The Cover - Miguel A. Castro
Understanding ASP.NET Under The Cover - Miguel A. Castro
 
Android development training programme , Day 3
Android development training programme , Day 3Android development training programme , Day 3
Android development training programme , Day 3
 
동기화 시대를 뛰어넘는 비동기 프로그래밍
동기화 시대를 뛰어넘는 비동기 프로그래밍동기화 시대를 뛰어넘는 비동기 프로그래밍
동기화 시대를 뛰어넘는 비동기 프로그래밍
 
Session 9 Android Web Services - Part 2.pdf
Session 9 Android Web Services - Part 2.pdfSession 9 Android Web Services - Part 2.pdf
Session 9 Android Web Services - Part 2.pdf
 
Asynchronous reading and writing http r equest
Asynchronous reading and writing http r equestAsynchronous reading and writing http r equest
Asynchronous reading and writing http r equest
 
Concurrency - responsiveness in .NET
Concurrency - responsiveness in .NETConcurrency - responsiveness in .NET
Concurrency - responsiveness in .NET
 
Implementing Comet using PHP
Implementing Comet using PHPImplementing Comet using PHP
Implementing Comet using PHP
 
JavaScript Lessons 2023
JavaScript Lessons 2023JavaScript Lessons 2023
JavaScript Lessons 2023
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)
 
course slides -- powerpoint
course slides -- powerpointcourse slides -- powerpoint
course slides -- powerpoint
 
Training – Going Async
Training – Going AsyncTraining – Going Async
Training – Going Async
 
Bot builder v4 HOL
Bot builder v4 HOLBot builder v4 HOL
Bot builder v4 HOL
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at Pinterest
 
2 Asp Dot Net Ajax Extensions
2 Asp Dot Net Ajax Extensions2 Asp Dot Net Ajax Extensions
2 Asp Dot Net Ajax Extensions
 

More from Wei Sun

Using google appengine_final
Using google appengine_finalUsing google appengine_final
Using google appengine_finalWei Sun
 
Using google appengine (2)
Using google appengine (2)Using google appengine (2)
Using google appengine (2)Wei Sun
 
Gc algorithm inside_dot_net
Gc algorithm inside_dot_netGc algorithm inside_dot_net
Gc algorithm inside_dot_netWei Sun
 
Code review
Code reviewCode review
Code reviewWei Sun
 
Windbg dot net_clr2
Windbg dot net_clr2Windbg dot net_clr2
Windbg dot net_clr2Wei Sun
 
The best way to learn java script
The best way to learn java scriptThe best way to learn java script
The best way to learn java scriptWei Sun
 
Code quality
Code qualityCode quality
Code qualityWei Sun
 
老友记
老友记老友记
老友记Wei Sun
 
Lua gc代码
Lua gc代码Lua gc代码
Lua gc代码Wei Sun
 
Windbg dot net_clr2
Windbg dot net_clr2Windbg dot net_clr2
Windbg dot net_clr2Wei Sun
 
Dotnetintroduce 100324201546-phpapp02
Dotnetintroduce 100324201546-phpapp02Dotnetintroduce 100324201546-phpapp02
Dotnetintroduce 100324201546-phpapp02Wei Sun
 
Code rule
Code ruleCode rule
Code ruleWei Sun
 
Web development overview
Web development overviewWeb development overview
Web development overviewWei Sun
 
DotNet Introduction
DotNet IntroductionDotNet Introduction
DotNet IntroductionWei Sun
 

More from Wei Sun (16)

Using google appengine_final
Using google appengine_finalUsing google appengine_final
Using google appengine_final
 
Using google appengine (2)
Using google appengine (2)Using google appengine (2)
Using google appengine (2)
 
Gc algorithm inside_dot_net
Gc algorithm inside_dot_netGc algorithm inside_dot_net
Gc algorithm inside_dot_net
 
Code review
Code reviewCode review
Code review
 
Windbg dot net_clr2
Windbg dot net_clr2Windbg dot net_clr2
Windbg dot net_clr2
 
The best way to learn java script
The best way to learn java scriptThe best way to learn java script
The best way to learn java script
 
Code quality
Code qualityCode quality
Code quality
 
老友记
老友记老友记
老友记
 
Lua gc代码
Lua gc代码Lua gc代码
Lua gc代码
 
Windbg dot net_clr2
Windbg dot net_clr2Windbg dot net_clr2
Windbg dot net_clr2
 
Dotnetintroduce 100324201546-phpapp02
Dotnetintroduce 100324201546-phpapp02Dotnetintroduce 100324201546-phpapp02
Dotnetintroduce 100324201546-phpapp02
 
Code rule
Code ruleCode rule
Code rule
 
Web development overview
Web development overviewWeb development overview
Web development overview
 
Lua
LuaLua
Lua
 
DotNet Introduction
DotNet IntroductionDotNet Introduction
DotNet Introduction
 
Mac
MacMac
Mac
 

Recently uploaded

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
[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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 

Recently uploaded (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
[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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 

Asynchronous in dot net4

  • 2.
  • 3.
  • 4. Action<object> action = (object obj) => { Console.WriteLine(&quot;Task={0}, obj={1}, Thread={2}&quot;, Task.CurrentId, obj.ToString(), Thread.CurrentThread.ManagedThreadId); }; // Construct an unstarted task Task t1 = new Task(action, &quot;alpha&quot;); // Cosntruct a started task Task t2 = Task.Factory.StartNew(action, &quot;beta&quot;); // Block the main thread to demonstate that t2 is executing t2.Wait(); // Launch t1 t1.Start(); Console.WriteLine(&quot;t1 has been launched. (Main Thread={0})&quot;, Thread.CurrentThread.ManagedThreadId); // Wait for the task to finish. You may optionally provide a timeout interval or a cancellation token to mitigate situations when the task takes too long to finish. t1.Wait(); // Construct an unstarted task Task t3 = new Task(action, &quot;gamma&quot;); // Run it synchronously t3.RunSynchronously(); // Although the task was run synchrounously, it is a good practice to wait for it which observes for // exceptions potentially thrown by that task. t3.Wait();
  • 5.
  • 6. public async Task<int> ExampleMethodAsync() { // . . . // At the await expression, execution in this method is suspended and, // if AwaitedProcessAsync has not already finished, control returns // to the caller of ExampleMethodAsync. int exampleInt = await AwaitedProcessAsync(); // . . . // The return statement completes the task. Any method that is // awaiting ExampleMethodAsync can now get the integer result. return exampleInt; }
  • 7. // An event handler must return void. private async void button1_Click(object sender, RoutedEventArgs e) { textBox1.Clear(); // SumPageSizesAsync returns a Task. await SumPageSizesAsync(); textBox1.Text += &quot;Control returned to button1_Click.&quot;; } // The following async lambda expression creates an equivalent anonymous // event handler. button1.Click += async (sender, e) => { textBox1.Clear(); // SumPageSizesAsync returns a Task. await SumPageSizesAsync(); textBox1.Text += &quot;Control returned to button1_Click.&quot;; }
  • 8. // The following async method returns a Task<T>. private async Task<byte[]> GetByteArrayAsync(Uri currentURI) { // Declare an HttpClient object. HttpClient client = new HttpClient(); // The GetAsync method returns a Task(Of T), where T is an HttpResponseMessage. Task<HttpResponseMessage> httpRMTask = client.GetAsync(currentURI); // Await httpRMTask evaluates to an HttpResponseMessage object. HttpResponseMessage httpRM = await httpRMTask; // The following line can replace the previous two assignment statements . //HttpResponseMessage httpRM = await client.GetAsync(currentURI); // Throw an exception if the HttpResponseMessage contains an error code. httpRM.EnsureSuccessStatusCode(); // Use ReadAsByteArray to access the content of the resource as a byte array. return httpRM.Content.ReadAsByteArray(); }
  • 9.
  • 10.
  • 11.
  • 12.
  • 13. public void AsyncIntroSerialBefore() { var client = new WebClient(); client.DownloadStringCompleted += AsyncIntroSerialBefore_DownloadStringCompleted_1; client.DownloadStringAsync(new Uri(&quot;http://www.weather.gov&quot;)); } void AsyncIntroSerialBefore_DownloadStringCompleted_1(object sender, DownloadStringCompletedEventArgs e) { WriteLinePageTitle(e.Result); var client = new WebClient(); client.DownloadStringCompleted += AsyncIntroSerialBefore_DownloadStringCompleted_2; client.DownloadStringAsync(new Uri(&quot;http://www.weather.gov/climate/&quot;)); } void AsyncIntroSerialBefore_DownloadStringCompleted_2(object sender, DownloadStringCompletedEventArgs e) { WriteLinePageTitle(e.Result); var client = new WebClient(); client.DownloadStringCompleted += AsyncIntroSerialBefore_DownloadStringCompleted_3; client.DownloadStringAsync(new Uri(&quot;http://www.weather.gov/rss/&quot;)); } void AsyncIntroSerialBefore_DownloadStringCompleted_3(object sender, DownloadStringCompletedEventArgs e) { WriteLinePageTitle(e.Result); } C# 4.0
  • 14. public async void AsyncIntroSerial() { var client = new WebClient(); WriteLinePageTitle(await client.DownloadStringTaskAsync(new Uri(&quot;http://www.weather.gov&quot;))); WriteLinePageTitle(await client.DownloadStringTaskAsync(new Uri(&quot;http://www.weather.gov/climate/&quot;))); WriteLinePageTitle(await client.DownloadStringTaskAsync(new Uri(&quot;http://www.weather.gov/rss/&quot;))); } Async