Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Future of C# and Visual Basic

Similar presentations


Presentation on theme: "The Future of C# and Visual Basic"— Presentation transcript:

1 The Future of C# and Visual Basic
5/18/2018 3:17 AM The Future of C# and Visual Basic Anders Hejlsberg Technical Fellow Microsoft Corporation © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista 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 the part 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.

2 C# and VB Evolution C# 4.0 + VB 10.0 Dynamic + Language Parity
Language Integrated Query C# VB 8.0 Generics C# VB 7.0 Managed Code

3 Trends Declarative Concurrent Dynamic

4 Trends Increasingly connected applications Asynchronous programming
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 C# and VB Evolution C# + VB v.Next Asynchronous Programming
Dynamic + Language Parity C# VB 9.0 Language Integrated Query C# VB 8.0 Generics C# VB 7.0 Managed Code

6 Asynchrony in a Nutshell
Synchronous  Wait for result before returning string DownloadString(...); Asynchronous  Return now, call back with result void DownloadStringAsync(..., Action<string> callback); Asynchrony benefits UI responsiveness: Frees UI thread for interaction Server scalability: Thread can be reused for other requests

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

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

9 Asynchronous Responsive UI
5/18/2018 3:17 AM Asynchronous Responsive UI demo © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista 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 the part 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.

10 Visual Studio Async CTP
5/18/2018 3:17 AM Visual Studio Async CTP announcing © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista 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 the part 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.

11 Asynchronous Methods Framework: Use Task<T> for all asynchrony
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

12 Task<T> Represents “ongoing operation” Composable callback model
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.

13 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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); } Message Pump UI Thread

14 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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); } t1

18 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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); } t1 t2

19 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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); } t1 t2

20 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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); } t1 t2

21 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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); } t1 t2

22 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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); } t1 t2

23 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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); } t1 t2

24 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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); } t1 t2

25 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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); } t1 t2

26 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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); } t1 t2

27 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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); } t1 t2

28 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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); } t1 t2

29 Asynchronous Control Flow
async void DoWorkAsync() { var t1 = ProcessFeedAsync(" var t2 = ProcessFeedAsync(" 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); } t1 t2

30 How Does it Work? 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 How Does it Work? Task<XElement> GetRssAsync(string url) {
var $builder = AsyncMethodBuilder<XElement>.Create(); var $state = 0; TaskAwaiter<string> $a1; Action $resume = delegate { try { if ($state == 1) goto L1; var client = new WebClient(); 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; }

32 Asynchronous Web Servers
5/18/2018 3:17 AM Asynchronous Web Servers demo © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista 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 the part 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.

33 Unifying Asynchrony An asynchronous scenario
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

34 Unifying Asynchrony Task CPU Network I/O Composite 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);

35 Download Visual Studio Async CTP today!
Asynchronous Methods As simple as synchronous code Unifies computational, network and I/O asynchrony More scalable servers More responsive UI Download Visual Studio Async CTP today!

36 C# and VB Evolution C# + VB v.Next Asynchronous Programming
Dynamic + Language Parity C# VB 9.0 Language Integrated Query C# VB 8.0 Generics C# VB 7.0 Managed Code

37 Compiler as a Service Compiler Compiler Meta-programming
Class Field public Foo private string X Meta-programming Read-Eval-Print Loop Language Object Model DSL Embedding Compiler Compiler Source File .NET Assembly Source code Source code Source code Source code

38 demo Compiler as a Service 5/18/2018 3:17 AM
© 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista 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 the part 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.

39 More Information Visual Studio Async CTP Related Talks
Related Talks LINQ, Take Two: Realizing the LINQ to Everything Dream Programming Languages Panel Building Web APIs for the Highly Connected Web The Future of F#: Data and Services at your Finger Tips

40 5/18/2018 3:17 AM © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista 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 the part 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. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista 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 the part 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.


Download ppt "The Future of C# and Visual Basic"

Similar presentations


Ads by Google