Your SlideShare is downloading. ×
0
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Async Development con Visual Studio 2012
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Async Development con Visual Studio 2012

1,000

Published on

La nuova versione di Visual Studio introduce il supporto al .NET Framework 4.5, a C# 5 e Visual Basic 11, che con nuove parole chiavi e nuovi compilatori, aprono le porte alla programmazione asincrona …

La nuova versione di Visual Studio introduce il supporto al .NET Framework 4.5, a C# 5 e Visual Basic 11, che con nuove parole chiavi e nuovi compilatori, aprono le porte alla programmazione asincrona Task based. In questa sessione verranno presentate le funzionalità legate a questo pattern, facendo un parallelo con gli approcci che fino ad oggi sono stati impiegati per risolvere i medesimi problemi.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,000
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. AsyncDevelopmentRaffaele Fanizziwww.vifani.com
  • 2. Cosa significa «concorrenza»?La capacità di eseguire o far sembrare inesecuzione due operazioni nello stesso momento
  • 3. Cosa significa «asincrono»?La capacità di eseguire un’operazione senza che ilrichiedente resti in attesa della fine della stessa
  • 4. delegate AsyncCallback(IAsyncResult); interface IAsyncResult { object AsyncState { get; } WaitHandle AsyncWaitHandle { get; } bool CompletedSynchronously { get; } bool IsCompleted { get; } } void BeginXxx(arg1, arg2, ..., AsyncCallback, state); TResult EndXxx(IAsyncResult);
  • 5. public static void Transfer(string url, Stream streamOut) { var request = WebRequest.Create(url); using (var response = request.GetResponse()) { var streamIn = response.GetResponseStream(); var size = 1024; var buffer = new byte[size]; while (true) { var lengthRead = streamIn.Read(buffer, 0, size); if (lengthRead <= 0) break; streamOut.Write(buffer, 0, lengthRead); } } }
  • 6. IAsyncResult BeginTransfer(url, streamOut, ..., callback) { // keep context and BeginGetResponse } void EndGetResponse(...) { // get streamIn and BeginRead } void EndRead(...) { // data read and BeginWrite } void EndWrite(...) { // data wrote and BeginRead }
  • 7. public void Transfer(string url, Stream streamOut) { try { var request = WebRequest.Create(url); using (var response = request.GetResponse()) { var streamIn = response.GetResponseStream(); var size = 1024; var buffer = new byte[size]; while (true) { var lengthRead = streamIn.Read(buffer, 0, size); if (lengthRead <= 0) break; streamIn.Write(buffer, 0, lengthRead); } } } catch { // ... } }
  • 8. IAsyncResult BeginTransfer(url, streamOut, ..., callback) { try { ... } catch { ... }}void EndGetResponse(...) { try { ... } catch { ... }}void EndRead(...) { try { ... } catch { ... }}void EndWrite(...) { try { ... } catch { ... }}
  • 9. class XxxCompletedEventArgs : EventArgs { Exception Error { get; } TResult Result { get; }}class Worker { event EventHandler<XxxCompletedArgs>XxxCompleted; void XxxAsync(arg1, arg2, ...);}
  • 10. public static void Transfer(string url, Stream streamOut) { var request = WebRequest.Create(url); using (var response = request.GetResponse()) { var streamIn = response.GetResponseStream(); var size = 1024; var buffer = new byte[size]; while (true) { var lengthRead = streamIn.Read(buffer, 0, size); if (lengthRead <= 0) break; streamOut.Write(buffer, 0, lengthRead); } } }
  • 11. public static async void Transfer(string url, Stream streamOut) { var request = WebRequest.Create(url); using (var response = await request.GetResponseAsync()) { var streamIn = response.GetResponseStream(); var size = 1024; var buffer = new byte[size]; while (true) { var lengthRead = await streamIn.ReadAsync(buffer, 0, size); if (lengthRead <= 0) break; await streamOut.WriteAsync(buffer, 0, lengthRead); } } }
  • 12. www.vifani.comhttp://msdn.microsoft.com/en-us/library/vstudio/hh191443.aspxhttp://msdn.microsoft.com/en-us/library/hh873177.aspx
  • 13. © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on thepart of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

×