@GiovanniBassi                 3
C# 4.0 + VB 10.0                                      Dinamismo + paridade nas                                      lingua...
C# 5.0 + VB 11.0                                          Programação assíncrona             C# 4.0 + VB 10.0             ...
var data = DownloadData(...);ProcessData(data);DownloadDataAsync(... , data => {    ProcessData(data);});
var data = DownloadData(...);ProcessData(data);DownloadDataAsync(... , data => {    ProcessData(data);});
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async void DoWorkAsync() {    var t1 = ProcessFeedAsync("www.acme.com/rss");    var t2 = ProcessFeedAsync("www.xyznews.com...
async Task<XElement> GetRssAsync(string url) {    var client = new WebClient();    var task = client.DownloadStringTaskAsy...
async Task<XElement> GetRssAsync(string url) {    var client = new WebClient();    var task = client.DownloadStringTaskAsy...
Task<XElement> GetRssAsync(string url) {                  var $builder = AsyncTaskMethodBuilder<XElement>.Create();async T...
Task<XElement> GetRssAsync(string url) {                  var $builder = AsyncTaskMethodBuilder<XElement>.Create();async T...
Task<XElement> GetRssAsync(string url) {                  var $builder = AsyncTaskMethodBuilder<XElement>.Create();async T...
Task<XElement> GetRssAsync(string url) {                  var $builder = AsyncTaskMethodBuilder<XElement>.Create();async T...
var feeds = (from url in urls select client.DownloadFeed(url)).ToArray();var feeds = await Task.WhenAll(from url in urls s...
try {    string[] videoUrls = await ScrapeYoutubeAsync(url);    // Rede    Task<Video> t1 = DownloadVideoAsync(videoUrls[0...


public static class Trace{    public static void WriteLine(string message,        [CallerFilePath] string file = "",      ...
public static class Trace{    public static void WriteLine(string message,        [CallerFilePath] string file = "",      ...
C# 5.0 + VB 11.0                                          Programação assíncrona             C# 4.0 + VB 10.0             ...
Class Meta-programação                        Read-Eval-Print Loop (REPL)                    public             FooModelo ...
Language  ServiceCompiler   APIsCompiler Pipeline   Metadata             Import
http://msdn.com/vstudio/async
o   30/Set 17:20, com Fabio Galuppoo   30/Set 10:10, com Rodrigo Vidalo   29/Set 17:10, com Victor Cavalcante e Giovanni B...
Get the free mobile app for your phonehttp:/ / gettag.mobi                                         http://technet.microsof...
Não esqueça depreencher sua avaliação        onlinewww.teched.com.br/avaliacao               Get the free mobile app for y...
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
C# e Visual Basic Future: Async Made Simple (DEV304)
Upcoming SlideShare
Loading in...5
×

C# e Visual Basic Future: Async Made Simple (DEV304)

1,665

Published on

Palestra ministrada no TechEd Brasil 2011 por Giovanni Bassi.
http://blog.lambda3.com.br

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

No Downloads
Views
Total Views
1,665
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

C# e Visual Basic Future: Async Made Simple (DEV304)

  1. 1. @GiovanniBassi 3
  2. 2. C# 4.0 + VB 10.0 Dinamismo + paridade nas linguagens C# 3.0 + VB 9.0 Language Integrated Query C# 2.0 + VB 8.0 GenericsC# 1.0 + VB 7.0 Código gerenciado
  3. 3. C# 5.0 + VB 11.0 Programação assíncrona C# 4.0 + VB 10.0 Dinamismo + paridade nas linguagens C# 3.0 + VB 9.0 Language Integrated Query C# 2.0 + VB 8.0 GenericsC# 1.0 + VB 7.0 Código gerenciado
  4. 4. var data = DownloadData(...);ProcessData(data);DownloadDataAsync(... , data => { ProcessData(data);});
  5. 5. var data = DownloadData(...);ProcessData(data);DownloadDataAsync(... , data => { ProcessData(data);});
  6. 6. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); }
  7. 7. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); }
  8. 8. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); }
  9. 9. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); }
  10. 10. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); }
  11. 11. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); }
  12. 12. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); }
  13. 13. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); } 
  14. 14. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); } 
  15. 15. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); }  
  16. 16. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); }  
  17. 17. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); }   
  18. 18. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); }    
  19. 19. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); }     
  20. 20. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); }      
  21. 21. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); }       
  22. 22. async void DoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); await Task.WhenAll(t1, t2); DisplayMessage("Done");} async Task ProcessFeedAsync(string url) { var text = await DownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); await SaveDocAsync(doc); ProcessLog.WriteEntry(url); }       
  23. 23. async Task<XElement> GetRssAsync(string url) { var client = new WebClient(); var task = client.DownloadStringTaskAsync(url); var text = await task; var xml = XElement.Parse(text); return xml;}
  24. 24. async Task<XElement> GetRssAsync(string url) { var client = new WebClient(); var task = client.DownloadStringTaskAsync(url); var text = await task; var xml = XElement.Parse(text); return xml;} Task<XElement> GetRssAsync(string url) { var client = new WebClient(); var task = client.DownloadStringTaskAsync(url); return task.ContinueWith(delegate { var text = task.Result; var xml = XElement.Parse(text); return xml; }); }
  25. 25. Task<XElement> GetRssAsync(string url) { var $builder = AsyncTaskMethodBuilder<XElement>.Create();async Task<XElement> $state = 0; var TaskAwaiter<string> $a1;GetRssAsync(string url) { Action $resume = delegate { var client = new try { WebClient(); var task = if ($state == 1) goto L1;client.DownloadStringTaskAsync(url);new WebClient(); var client = var text = await task; task = client.DownloadStringTaskAsync(url); var $a1 = task.GetAwaiter(); var xml = XElement.Parse(text); return xml; if ($a1.IsCompleted) goto L1;} $state = 1; $a1.OnCompleted($resume); return; L1: var text = $a1.GetResult(); var xml = XElement.Parse(text); $builder.SetResult(xml); } catch (Exception $ex) { $builder.SetException($ex); } }; $resume(); return $builder.Task; }
  26. 26. Task<XElement> GetRssAsync(string url) { var $builder = AsyncTaskMethodBuilder<XElement>.Create();async Task<XElement> $state = 0; var TaskAwaiter<string> $a1;GetRssAsync(string url) { Action $resume = delegate { var client = new try { WebClient(); var task = if ($state == 1) goto L1;client.DownloadStringTaskAsync(url);new WebClient(); var client = var text = await task; task = client.DownloadStringTaskAsync(url); var $a1 = task.GetAwaiter(); var xml = XElement.Parse(text); return xml; if ($a1.IsCompleted) goto L1;} $state = 1; $a1.OnCompleted($resume); return; L1: var text = $a1.GetResult(); var xml = XElement.Parse(text); $builder.SetResult(xml); } catch (Exception $ex) { $builder.SetException($ex); } }; $resume(); return $builder.Task; }
  27. 27. Task<XElement> GetRssAsync(string url) { var $builder = AsyncTaskMethodBuilder<XElement>.Create();async Task<XElement> $state = 0; var TaskAwaiter<string> $a1;GetRssAsync(string url) { Action $resume = delegate { var client = new try { WebClient(); var task = if ($state == 1) goto L1;client.DownloadStringTaskAsync(url);new WebClient(); var client = var text = await task; task = client.DownloadStringTaskAsync(url); var $a1 = task.GetAwaiter(); var xml = XElement.Parse(text); return xml; if ($a1.IsCompleted) goto L1;} $state = 1; $a1.OnCompleted($resume); return; L1: var text = $a1.GetResult(); var xml = XElement.Parse(text); $builder.SetResult(xml); } catch (Exception $ex) { $builder.SetException($ex); } }; $resume(); return $builder.Task; }
  28. 28. Task<XElement> GetRssAsync(string url) { var $builder = AsyncTaskMethodBuilder<XElement>.Create();async Task<XElement> $state = 0; var TaskAwaiter<string> $a1;GetRssAsync(string url) { Action $resume = delegate { var client = new try { WebClient(); var task = if ($state == 1) goto L1;client.DownloadStringTaskAsync(url);new WebClient(); var client = var text = await task; task = client.DownloadStringTaskAsync(url); var $a1 = task.GetAwaiter(); var xml = XElement.Parse(text); return xml; if ($a1.IsCompleted) goto L1;} $state = 1; $a1.OnCompleted($resume); return; L1: var text = $a1.GetResult(); var xml = XElement.Parse(text); $builder.SetResult(xml); } catch (Exception $ex) { $builder.SetException($ex); } }; $resume(); return $builder.Task; }
  29. 29. var feeds = (from url in urls select client.DownloadFeed(url)).ToArray();var feeds = await Task.WhenAll(from url in urls select client.DownloadFeedAsync(url)); Sem novas threads!
  30. 30. try { string[] videoUrls = await ScrapeYoutubeAsync(url); // Rede Task<Video> t1 = DownloadVideoAsync(videoUrls[0]); // Baixe 2 videos Task<Video> t2 = DownloadVideoAsync(videoUrls[1]); Video[] vids = await Task.WhenAll(t1, t2); // Espere os 2 Video v = await MashupVideosAsync(vids[0], vids[1]); // CPU await v.SaveAsync(textbox.Text); // Entrada/Saída}catch (WebException ex) { ReportError(ex);}
  31. 31. 
  32. 32. 
  33. 33. public static class Trace{ public static void WriteLine(string message, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0, [CallerMemberName] string member = "") { var s = string.Format("{0}:{1} – {2}: {3}", file, line, member, message); Console.WriteLine(s); }}Trace.WriteLine("Starting services"); Trace.WriteLine("Starting services", "c:sourcesfoo.cs", 1123, "Initialize");
  34. 34. public static class Trace{ public static void WriteLine(string message, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0, [CallerMemberName] string member = "") { var s = string.Format("{0}:{1} – {2}: {3}", file, line, member, message); Console.WriteLine(s); }}Trace.WriteLine("Starting services"); Trace.WriteLine("Starting services", "c:sourcesfoo.cs", 1123, "Initialize");
  35. 35. C# 5.0 + VB 11.0 Programação assíncrona C# 4.0 + VB 10.0 Dinamismo + paridade nas linguagens C# 3.0 + VB 9.0 Language Integrated Query C# 2.0 + VB 8.0 GenericsC# 1.0 + VB 7.0 Código gerenciado
  36. 36. Class Meta-programação Read-Eval-Print Loop (REPL) public FooModelo de objetos Field Incorporação de DSLs da linguagem private X string Código Assembly Source Fonte Source .NET Source code Compilador Source code code code
  37. 37. Language ServiceCompiler APIsCompiler Pipeline Metadata Import
  38. 38. http://msdn.com/vstudio/async
  39. 39. o 30/Set 17:20, com Fabio Galuppoo 30/Set 10:10, com Rodrigo Vidalo 29/Set 17:10, com Victor Cavalcante e Giovanni Bassi
  40. 40. Get the free mobile app for your phonehttp:/ / gettag.mobi http://technet.microsoft.com/pt-brGet the free mobile app for your phonehttp:/ / gettag.mobi http://msdn.microsoft.com/pt-br
  41. 41. Não esqueça depreencher sua avaliação onlinewww.teched.com.br/avaliacao Get the free mobile app for your phone http:/ / gettag.mobi

×