1 / 37

The Future of C # and Visual Basic

Kevin Pilch-Bisson Dev Lead for C# and Visual Basic IDE Services Microsoft Corporation. The Future of C # and Visual Basic. C# and VB Evolution. C# + VB v.Next. Asynchronous Programming. C# 4.0 + VB 10.0. Dynamic + Language Parity. C# 3.0 + VB 9.0. Language Integrated Query.

janus
Download Presentation

The Future of C # and Visual Basic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Kevin Pilch-Bisson Dev Lead for C# and Visual Basic IDE Services Microsoft Corporation The Future of C# andVisual Basic

  2. C# and VB Evolution C# + VB v.Next 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 Generics C# 1.0 + VB 7.0 Managed Code

  3. Trends

  4. Asynchronous Programming • Increasingly connected applications • More latency • More UI responsiveness problems • More scalability issues • Asynchronous programming • Becoming the norm in responsive, scalable apps • Async-only APIs, e.g. JavaScript and Silverlight

  5. Asynchrony in a Nutshell • Synchronous Wait for result before returning • string DownloadString(...); • Asynchronous Return now, call back with result • void DownloadStringAsync(..., Action<string> callback); • Sharing Threads between activities • UI responsiveness: Free UI thread for user interaction • Server scalability: Reuse thread for other requests

  6. Synchronous vs. Asynchronous var data = DownloadData(...); ProcessData(data); STOP Thread DownloadData ProcessData DownloadDataAsync(... , data => { ProcessData(data); }); Thread DownloadDataAsync ProcessData

  7. Synchronous vs. Asynchronous var data = DownloadData(...); ProcessData(data); STOP STOP Thread DownloadData ProcessData DownloadDataAsync(... , data => { ProcessData(data); }); Thread DownloadDataAsync ProcessData

  8. Asynchronous Responsive UI demo

  9. Visual Studio Async CTP http://msdn.com/vstudio/async Announcing

  10. Asynchronous Methods • Goal: Just like synchronous programming • You can have your cake and eat it too! • Framework: Use Task<T> for all asynchrony • Add Task<T> support to existing .NET and Silverlight APIs • Easy for you to do the same • Languages: Asynchronous Methods • “async” modifier marks method or lambda as asynchronous • “await” operator yields control until awaited task completes

  11. Task<T> • Represents “ongoing operation” • Could be async I/O, background worker, anything... • Single object for status, result and exceptions • Composable callback model • var task2 = task1.ContinueWith(t => … t.Result …); • The “await” operator rewrites to continuations • Combinators • WhenAll, WhenAny, Delay, etc.

  12. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); } MessagePump UI Thread

  13. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); }

  14. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); }

  15. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); }

  16. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); } t1

  17. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); } t1 t2

  18. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); } t1 t2

  19. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); } t1 t2 

  20. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); } t1 t2 

  21. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); } t1 t2  

  22. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); } t1 t2  

  23. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); } t1 t2   

  24. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); } t1 t2    

  25. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); } t1 t2     

  26. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); } t1 t2      

  27. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); } t1 t2       

  28. Asynchronous Control Flow async voidDoWorkAsync() { var t1 = ProcessFeedAsync("www.acme.com/rss"); var t2 = ProcessFeedAsync("www.xyznews.com/rss"); awaitTask.WhenAll(t1, t2); DisplayMessage("Done"); } asyncTaskProcessFeedAsync(stringurl) { var text = awaitDownloadFeedAsync(url); var doc = ParseFeedIntoDoc(text); awaitSaveDocAsync(doc); ProcessLog.WriteEntry(url); } t1 t2       

  29. How Does it Work? async Task<XElement> GetRssAsync(stringurl) { var client = newWebClient(); var task = client.DownloadStringTaskAsync(url); var text = await task; var xml = XElement.Parse(text); return xml; }

  30. How Does it Work? Task<XElement> GetRssAsync(stringurl) { var $builder = AsyncMethodBuilder<XElement>.Create(); var $state = 0; TaskAwaiter<string> $a1; Action $resume = delegate { try { if ($state == 1) goto L1; var client = newWebClient(); var task = client.DownloadStringTaskAsync(url); $state = 1; $a1 = task.GetAwaiter(); if ($a1.BeginAwait($resume)) return; L1: var text = $a1.EndAwait(); var xml = XElement.Parse(text); $builder.SetResult(xml); } catch (Exception $ex) { $builder.SetException($ex); } }; $resume(); return $builder.Task; } 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; }

  31. Asynchronous Web Servers demo

  32. Unifying Asynchrony Asynchronous Methods Task • An asynchronous scenario • Scrape YouTube for video links • Download two or more videos concurrently • Create a mashup from downloaded videos • Save the resulting video CPU Network I/O Composite

  33. Unifying Asynchrony Task CPU Network I/O Composite try { string[] videoUrls = awaitScrapeYoutubeAsync(url); // Network-bound Task<Video> t1 = DownloadVideoAsync(videoUrls[0]);// Start two downloads Task<Video> t2 = DownloadVideoAsync(videoUrls[1]); Video[] vids = awaitTask.WhenAll(t1, t2); // Wait for both Video v = awaitMashupVideosAsync(vids[0], vids[1]); // CPU-bound awaitv.SaveAsync(textbox.Text); // IO-bound } catch (WebException ex) { ReportError(ex); }

  34. Asynchronous Methods • More responsive UI, more scalable servers • Unifies computational, network and I/O asynchrony • No more callbacks! DownloadVisual Studio Async CTPtoday!

  35. Update – Compiler as a Service Class Language Object Model Read-Eval-Print Loop public Foo Field DSL Embedding Metaprogramming string x private Source Code C# Compiler .Net Assemblies

  36. Compiler as a Service demo

  37. http://msdn.com/vstudio/async http://twitter.com/Pilchie kevinpi@microsoft.com Questions?

More Related