Presentation is loading. Please wait.

Presentation is loading. Please wait.

Future of VB and C# Lucian Wischik VB Language PM Microsoft.

Similar presentations


Presentation on theme: "Future of VB and C# Lucian Wischik VB Language PM Microsoft."— Presentation transcript:

1 Future of VB and C# Lucian Wischik VB Language PM Microsoft

2 This is Vegas WIN BIG MONEY !!! Each speaker- eval earns $5 to Doctors Without Borders. Drop off at registration desk.

3 History Managed Code Generics LINQ Co-evolution C#1, VB7 C#2, VB8 C#4, VB10 C#3, VB9

4 History Async Managed Code Generics LINQ Co-evolution C#1, VB7 C#2, VB8 C#4, VB10 C# vNext, VB11 C#3, VB9

5 History Async Managed Code Generics LINQ Co-evolution C#1, VB7 C#2, VB8 C#4, VB10 C# vNext, VB11 C#3, VB9 ??? “Roslyn”

6 History Async, Win8, CallerInfo VB: VBCore, Global, Iterators Managed Code Generics, EnC, My, partial, nullables, XML-comments LINQ, lambdas, XML literals, type inference, extensions Co-evolution, NOPIA, Dynamic/DLR, covariance C#1, VB7 C#2, VB8 C#4, VB10 C# vNext, VB11 C#3, VB9 ??? “Roslyn” ???

7 History Async, Win8, CallerInfo, VB: VBCore, Global, Iterators Managed Code Generics, EnC, My, partial, nullables, XML-comments LINQ, lambdas, XML literals, type inference, extensions Co-evolution, NOPIA, Dynamic/DLR, covariance C#1, VB7 C#2, VB8 C#4, VB10 C# vNext, VB11 C#3, VB9 ??? “Roslyn” ??? Async CallerInfo Roslyn

8 Async is a new, easier way to write connected apps. In the past… ● “Connected” has generally meant either a UI that freezes, or unmaintainable spaghetti code, or multithreading. C# and VB future: Async… ● Two new keywords: Await and Async in VB and C# ● A new Task-based design pattern for APIs, the "T.A.P." (Task Asynchronous Pattern) ● A new set of.NET Framework APIs Async CallerInfo Roslyn

9 Async is a new, easier way to write connected apps. In the past… ● “Connected” has generally meant either a UI that freezes, or unmaintainable spaghetti code, or multithreading. C# and VB future: Async… ● Two new keywords: Await and Async in VB and C# ● A new Task-based design pattern for APIs, the "T.A.P." (Task Asynchronous Pattern) ● A new set of.NET Framework APIs Async CallerInfo Roslyn Fundamentals Demo How it works Big picture

10 Async: Fundamentals

11 webClient.UploadString(uri); print("done"); webClient.UploadString(uri); print("done");

12

13 “A waiter’s job is to wait on a table until the patrons have finished their meal. If you want to serve two tables concurrently, you must hire two waiters.”

14 The following is from the Android dev blog. Can you spot the flaw? 1. “A good practice in creating responsive applications is to make sure your main UI thread does the minimum amount of work.” 2. “Any potentially long task that may hang your application should be handled in a different thread.” 3. “Typical examples of such tasks are network operations, which involve unpredictable delays.”

15 How best to explain the sequence of events in a restaurant with several tables? From the perspective of the patrons? or of the waiter?

16

17 Demo: async

18

19 This is the IL that’s emitted when you using async/await Async: How it works

20 async Task GetDiggAsync() { var web = new WebClient(); var downTask = web.DownTaskAsync("http://digg.com"); var rss = await downTask; var digg = XElement.Parse(rss).. ; return digg; } async void button1_Click() { var diggTask = GetDiggAsync(); var digg = await diggTask; textBox1.Text = digg; } UI thread IOCP thread Async: How it works

21 async void button1_Click() { var diggTask = GetDiggAsync(); var digg = await diggTask; textBox1.Text = digg; } async Task GetDiggAsync() { var web = new WebClient(); var downTask = web.DownTaskAsync("http://digg.com"); var rss = await downTask; var digg = XElement.Parse(rss).. ; return digg; } UI thread IOCP thread Click [1/12] A button-click arrives on the UI queue

22 async void button1_Click() { var diggTask = GetDiggAsync(); var digg = await diggTask; textBox1.Text = digg; } async Task GetDiggAsync() { var web = new WebClient(); var downTask = web.DownTaskAsync("http://digg.com"); var rss = await downTask; var digg = XElement.Parse(rss).. ; return digg; } UI thread IOCP thread Click downTask [2/12] Invoke some functions; get back “downTask” from the API

23 async Task GetDiggAsync() { var web = new WebClient(); var downTask = web.DownTaskAsync("http://digg.com"); var rss = await downTask; var digg = XElement.Parse(rss).. ; return digg; } downTask async void button1_Click() { var diggTask = GetDiggAsync(); var digg = await diggTask; textBox1.Text = digg; } UI thread IOCP thread Click downTask » sc.Post{Κ1} [3/12] “await downTask” assigns a continuation and returns diggTask Κ1: diggTask

24 async void button1_Click() { var diggTask = GetDiggAsync(); var digg = await diggTask; textBox1.Text = digg; } diggTask async Task GetDiggAsync() { var web = new WebClient(); var downTask = web.DownTaskAsync("http://digg.com"); var rss = await downTask; var digg = XElement.Parse(rss).. ; return digg; } UI thread IOCP thread Click downTask » sc.Post{Κ1} [4/12] “await diggTask” assigns a continuation and returns Κ1: Κ2: diggTask » sc.Post{Κ2}

25 async void button1_Click() { var diggTask = GetDiggAsync(); var digg = await diggTask; textBox1.Text = digg; } async Task GetDiggAsync() { var web = new WebClient(); var downTask = web.DownTaskAsync("http://digg.com"); var rss = await downTask; var digg = XElement.Parse(rss).. ; return digg; } UI thread IOCP thread Click rss [5/12] Network packet arrives with data downTask » sc.Post{Κ1} Κ1: Κ2: diggTask » sc.Post{Κ2}

26 async void button1_Click() { var diggTask = GetDiggAsync(); var digg = await diggTask; textBox1.Text = digg; } async Task GetDiggAsync() { var web = new WebClient(); var downTask = web.DownTaskAsync("http://digg.com"); var rss = await downTask; var digg = XElement.Parse(rss).. ; return digg; } UI thread IOCP thread Click rss sc.Post{Κ1(rss)} [6/12] Invoke downTask’s continuation with that data downTask » sc.Post{Κ1} Κ1: Κ2: diggTask » sc.Post{Κ2}

27 async void button1_Click() { var diggTask = GetDiggAsync(); var digg = await diggTask; textBox1.Text = digg; } async Task GetDiggAsync() { var web = new WebClient(); var downTask = web.DownTaskAsync("http://digg.com"); var rss = await downTask; var digg = XElement.Parse(rss).. ; return digg; } UI thread IOCP thread Click diggTask » sc.Post{Κ2} rss K1(rss) [7/12] Continuation is a “Post”, i.e. addition to the UI queue Κ1: Κ2: sc.Post{Κ1(rss)}

28 async void button1_Click() { var diggTask = GetDiggAsync(); var digg = await diggTask; textBox1.Text = digg; } async Task GetDiggAsync() { var web = new WebClient(); var downTask = web.DownTaskAsync("http://digg.com"); var rss = await downTask; var digg = XElement.Parse(rss).. ; return digg; } UI thread IOCP thread Click rss K1(rss) [8/12] UI thread executes K1, giving a result to the “await” Κ1: Κ2: sc.Post{Κ1(rss)} diggTask » sc.Post{Κ2}

29 async void button1_Click() { var diggTask = GetDiggAsync(); var digg = await diggTask; textBox1.Text = digg; } async Task GetDiggAsync() { var web = new WebClient(); var downTask = web.DownTaskAsync("http://digg.com"); var rss = await downTask; var digg = XElement.Parse(rss).. ; return digg; } UI thread IOCP thread Click rss K1(rss) [9/12] “Return story” will signal completion of task Κ1: Κ2: sc.Post{Κ1(rss)} diggTask » sc.Post{Κ2}

30 async void button1_Click() { var diggTask = GetDiggAsync(); var digg = await diggTask; textBox1.Text = digg; } async Task GetDiggAsync() { var web = new WebClient(); var downTask = web.DownTaskAsync("http://digg.com"); var rss = await downTask; var digg = XElement.Parse(rss).. ; return digg; } UI thread IOCP thread Click rss K1(rss) sc.Post(Κ2(story)) [10/12] Invoke diggTask’s continuation with data (by posting to UI queue) K2(story) Κ1: Κ2: sc.Post{Κ1(rss)} diggTask » sc.Post{Κ2}

31 async void button1_Click() { var diggTask = GetDiggAsync(); var digg = await diggTask; textBox1.Text = digg; } async Task GetDiggAsync() { var web = new WebClient(); var downTask = web.DownTaskAsync("http://digg.com"); var rss = await downTask; var digg = XElement.Parse(rss).. ; return digg; } UI thread IOCP thread Click rss K1(rss) sc.Post(Κ2(story)) K2(story) [11/12] Return from handling the K1 continuation Κ1: Κ2: sc.Post{Κ1(rss)}

32 async void button1_Click() { var diggTask = GetDiggAsync(); var digg = await diggTask; textBox1.Text = digg; } async Task GetDiggAsync() { var web = new WebClient(); var downTask = web.DownTaskAsync("http://digg.com"); var rss = await downTask; var digg = XElement.Parse(rss).. ; return digg; } rss K2(story) Click K1(rss) UI thread IOCP thread sc.Post(Κ2(story)) Κ1: Κ2: [12/12] UI thread executes K2, giving a result to the “await” sc.Post{Κ1(rss)}

33 SINGLE-THREADED ASYNCHRONY AND CONCURRENCY is when we run asynchronous and concurrent tasks with NO additional threads (beyond those that the operating system already provides). No worries about mutexes &c. If you want extra threads, create them explicitly through Task.Run. SINGLE-THREADED ASYNCHRONY AND CONCURRENCY is when we run asynchronous and concurrent tasks with NO additional threads (beyond those that the operating system already provides). No worries about mutexes &c. If you want extra threads, create them explicitly through Task.Run.

34  2008: Silverlight2: all its lengthy APIs are async  2010: [Feb] Windows Phone 7: all its lengthy APIs are async  2004: Asynchronous javascript (AJAX) hits big-time Async: big picture

35  2008: Silverlight2: all its lengthy APIs are async  2010: [Feb] Windows Phone 7: all its lengthy APIs are async  2004: Asynchronous javascript (AJAX) hits big-time Async: big picture

36  2008: Silverlight2: all its lengthy APIs are async  2010: [Feb] Windows Phone 7: all its lengthy APIs are async  2004: Asynchronous javascript (AJAX) hits big-time Async: big picture

37  2008: Silverlight2: all its lengthy APIs are async  2010: [Feb] Windows Phone 7: all its lengthy APIs are async  2004: Asynchronous javascript (AJAX) hits big-time Async: big picture

38 TASK UNIFIES ALL THESE AREAS; ASYNC TIES THEM TOGETHER Use Async Functions to compose other tasks, for the “orchestration” of your app async Task DoWorkAsync() { try { string[] vidUrls = await ScrapeYoutubeAsync(url); // Network-bound Task t1 = DownloadVideoAsync(vidUrls(0)); // Start 2 downloads Task t2 = DownloadVideoAsync(vidUrls(1)); Video[] vids = await TaskEx.WhenAll(t1, t2); // Wait for both Video v = await MashupVideosAsync(vids(0), vids(1)); // CPU-bound await v.SaveAsync(textbox1.Text); // IO-bound } catch (WebException ex) { ReportError(ex); } } async Task DoWorkAsync() { try { string[] vidUrls = await ScrapeYoutubeAsync(url); // Network-bound Task t1 = DownloadVideoAsync(vidUrls(0)); // Start 2 downloads Task t2 = DownloadVideoAsync(vidUrls(1)); Video[] vids = await TaskEx.WhenAll(t1, t2); // Wait for both Video v = await MashupVideosAsync(vids(0), vids(1)); // CPU-bound await v.SaveAsync(textbox1.Text); // IO-bound } catch (WebException ex) { ReportError(ex); } }

39 Async CallerInfo Roslyn

40 CallerInfo will help with logging and in boilerplate code like INotifyPropertyChanged. void Log([CallerLineNumber] int line = 0, [CallerFilePath] string f = null, [CallerMemberName] string m = null) { Console.WriteLine(“{0}:{1} - {2}”, f, line, m); } Async CallerInfo Roslyn

41 Demo: CallerInfo

42 Async CallerInfo Roslyn

43 is about opening up the internals of the compiler to let everyone use the VB/C# languages in powerful ways. Async CallerInfo Roslyn

44 is about opening up the internals of the compiler to let everyone use the VB/C# languages in powerful ways. Async CallerInfo Roslyn

45 IL emit Binder Symbols Metaimp Parser

46 IL emit Binder Symbols Metaimp Parser Syntax tree API Symbol API Bind/flow API Emit API

47 IL emit Binder Symbols Metaimp Parser Syntax tree API Symbol API Bind/flow API Emit API Colorizer Formatter Outlining NavigateTo ObjBrowser GoToDef ExtractMeth QuickInfo Rename FindAllRefs IntellisenseEnC

48 IL emit Binder Symbols Metaimp Parser Syntax tree API Symbol API Bind/flow API Emit API Colorizer Formatter Outlining NavigateTo ObjBrowser GoToDef ExtractMeth QuickInfo Rename FindAllRefs IntellisenseEnC Interactive “REPL” window Script files (think.vbs) --.csx.vbx Use C#/VB as scripting languages for your app

49 Demo: Roslyn

50 Async CallerInfo Roslyn

51 Async Download the Async CTP http://msdn.com/async http://msdn.com/async Start making Task-returning APIs today CallerInfo Wait patiently… Roslyn Download the Roslyn CTP http://msdn.com/roslyn http://msdn.com/roslyn Give us feedback Async CallerInfo Roslyn

52 Module Module1 Sub Main() Dim robots = {"Number5", "Asimo", "Cylon"} Dim xml = Robot Status <%= Iterator Function() For Each r In robots Yield Robot reporting for duty Next End Function() %> Console.WriteLine(xml) End Sub End Module A parting word from VB: ITERATOR LAMBDAS! A parting word from VB: ITERATOR LAMBDAS!


Download ppt "Future of VB and C# Lucian Wischik VB Language PM Microsoft."

Similar presentations


Ads by Google