Async                       connected programs• No more callbacks!
C# 4.0 + VB 10.0                                       Dynamic + Language Parity          C# 3.0 + VB 9.0                 ...
DeclarativeDynamic       Concurrent
C# 5.0 + VB 11.0                                           Asynchronous Programming              C# 4.0 + VB 10.0         ...
var data = DownloadData(...);ProcessData(data);DownloadDataAsync(... , data => {    ProcessData(data);});
var data = DownloadData(...);ProcessData(data);DownloadDataAsync(... , data => {    ProcessData(data);});
Demo
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>....
Task<XElement> GetRssAsync(string url) {                                  var $builder = AsyncTaskMethodBuilder<XElement>....
Others…WindowsPresentation      ASP.NETFoundation
try {    string[] videoUrls = await ScrapeYoutubeAsync(url);    // Network-bound    Task<Video> t1 = DownloadVideoAsync(vi...
C# 5.0 + VB 11.0                                            Asynchronous Programming              C# 4.0 + VB 10.0        ...
Meta-programming                                  Read-Eval-Print Loop                             Class                  ...
Demo
http://aka.ms/mbl-techhttp://aka.ms/mbl-tech/devprevhttp://aka.ms/mbl-tech/html5
Visual Studio Async CTP http://msdn.com/async
Microsoft “Roslyn” CTP http://msdn.com/roslyn
Students to Business Day 2012: Alex Turner
Students to Business Day 2012: Alex Turner
Students to Business Day 2012: Alex Turner
Students to Business Day 2012: Alex Turner
Students to Business Day 2012: Alex Turner
Students to Business Day 2012: Alex Turner
Students to Business Day 2012: Alex Turner
Upcoming SlideShare
Loading in …5
×

Students to Business Day 2012: Alex Turner

1,618 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
1,618
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Students to Business Day 2012: Alex Turner

  1. 1. Async connected programs• No more callbacks!
  2. 2. C# 4.0 + VB 10.0 Dynamic + Language Parity C# 3.0 + VB 9.0 Language Integrated Query C# 2.0 + VB 8.0 GenericsC# 1.0 + VB 7.0 Managed Code
  3. 3. DeclarativeDynamic Concurrent
  4. 4. C# 5.0 + VB 11.0 Asynchronous Programming C# 4.0 + VB 10.0 Dynamic + Language Parity C# 3.0 + VB 9.0 Language Integrated Query C# 2.0 + VB 8.0 GenericsC# 1.0 + VB 7.0 Managed Code
  5. 5. var data = DownloadData(...);ProcessData(data);DownloadDataAsync(... , data => { ProcessData(data);});
  6. 6. var data = DownloadData(...);ProcessData(data);DownloadDataAsync(... , data => { ProcessData(data);});
  7. 7. Demo
  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 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); }       
  24. 24. 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); }       
  25. 25. 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;}
  26. 26. 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; }); }
  27. 27. Task<XElement> GetRssAsync(string url) { var $builder = AsyncTaskMethodBuilder<XElement>.Create(); var $state = 0;async Task<XElement> GetRssAsync(string url) { $a1; TaskAwaiter<string> var client = new WebClient(); Action $resume = delegate { try { var task = client.DownloadStringTaskAsync(url); if ($state == 1) goto L1; var text = await task; var client = new WebClient(); var xml = XElement.Parse(text); var task = client.DownloadStringTaskAsync(url); $a1 = task.GetAwaiter(); 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(); var $state = 0;async Task<XElement> GetRssAsync(string url) { $a1; TaskAwaiter<string> var client = new WebClient(); Action $resume = delegate { try { var task = client.DownloadStringTaskAsync(url); if ($state == 1) goto L1; var text = await task; var client = new WebClient(); var xml = XElement.Parse(text); var task = client.DownloadStringTaskAsync(url); $a1 = task.GetAwaiter(); 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. Others…WindowsPresentation ASP.NETFoundation
  30. 30. try { string[] videoUrls = await ScrapeYoutubeAsync(url); // Network-bound Task<Video> t1 = DownloadVideoAsync(videoUrls[0]); // Start two downloads Task<Video> t2 = DownloadVideoAsync(videoUrls[1]); Video[] vids = await Task.WhenAll(t1, t2); // Wait for both Video v = await MashupVideosAsync(vids[0], vids[1]); // CPU-bound await v.SaveAsync(textbox.Text); // IO-bound}catch (WebException ex) { ReportError(ex);}
  31. 31. C# 5.0 + VB 11.0 Asynchronous Programming C# 4.0 + VB 10.0 Dynamic + Language Parity C# 3.0 + VB 9.0 Language Integrated Query C# 2.0 + VB 8.0 GenericsC# 1.0 + VB 7.0 Managed Code
  32. 32. Meta-programming Read-Eval-Print Loop Class public Foo Language Field DSL Embedding Object Model private X string Source .NET File Source code Assembly Source code Source code Compiler Source code
  33. 33. Demo
  34. 34. http://aka.ms/mbl-techhttp://aka.ms/mbl-tech/devprevhttp://aka.ms/mbl-tech/html5
  35. 35. Visual Studio Async CTP http://msdn.com/async
  36. 36. Microsoft “Roslyn” CTP http://msdn.com/roslyn

×