Future of VB and C# Lucian Wischik VB Language PM Microsoft This is Vegas WIN BIG MONEY !!! Each speakereval earns $5 to Doctors Without Borders. Drop off at registration desk.

Download Report

Transcript Future of VB and C# Lucian Wischik VB Language PM Microsoft This is Vegas WIN BIG MONEY !!! Each speakereval earns $5 to Doctors Without Borders. Drop off at registration desk.

Future of VB and C#
Lucian Wischik
VB Language PM
Microsoft
This is Vegas
WIN BIG
MONEY !!!
Each speakereval earns $5
to Doctors
Without
Borders.
Drop off at
registration
desk.
History
C#4, VB10
C#3, VB9
Co-evolution
LINQ
C#2, VB8
Generics
C#1, VB7
Managed Code
History
C# vNext, VB11
C#4, VB10
C#3, VB9
Co-evolution
LINQ
C#2, VB8
Generics
C#1, VB7
Async
Managed Code
History
???
C# vNext, VB11
C#4, VB10
C#3, VB9
Co-evolution
LINQ
C#2, VB8
Generics
C#1, VB7
Async
Managed Code
“Roslyn”
History
???
“Roslyn”
???
C# vNext, VB11
C#4, VB10
C#3, VB9
Async, Win8, CallerInfo
VB: VBCore, Global, Iterators
Co-evolution, NOPIA,
Dynamic/DLR, covariance
LINQ, lambdas, XML literals,
type inference, extensions
C#2, VB8
Generics, EnC, My, partial,
nullables, XML-comments
C#1, VB7
Managed Code
History
Async
???
“Roslyn”
???
C# vNext, VB11
CallerInfo
C#4, VB10
C#3, VB9
Roslyn
Async, Win8, CallerInfo,
VB: VBCore, Global, Iterators
Co-evolution, NOPIA,
Dynamic/DLR, covariance
LINQ, lambdas, XML literals,
type inference, extensions
C#2, VB8
Generics, EnC, My, partial,
nullables, XML-comments
C#1, VB7
Managed Code
Async
Async is a new, easier way
to write connected apps.
In the past…
●
CallerInfo
“Connected” has generally meant either a
UI that freezes, or unmaintainable
spaghetti code, or multithreading.
C# and VB future: Async…
●
Roslyn
●
●
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
Fundamentals
Async is a new, easier way
to write connected apps.
In the past…
●
Demo
CallerInfo
How it works
Big picture
C# and VB future: Async…
●
Roslyn
“Connected” has generally meant either a
UI that freezes, or unmaintainable
spaghetti code, or multithreading.
●
●
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: Fundamentals
webClient.UploadString(uri);
print("done");
“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.”
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.”
How best to explain the sequence of events in a restaurant
with several tables?
From the perspective of the patrons?
or of the waiter?
Demo: async
Demo: async
Async: How it works
This is the IL that’s emitted when
you using async/await
Async: How it works
UI
thread
async void button1_Click()
{ var diggTask = GetDiggAsync();
async Task<string> GetDiggAsync()
{ var web = new WebClient();
var downTask = web.DownTaskAsync("http://digg.com");
var rss = await downTask;
var digg = await diggTask;
var digg = XElement.Parse(rss).<story>.<description>;
return digg;
}
textBox1.Text = digg;
}
IOCP
thread
UI
thread
Click
[1/12] A button-click arrives on the UI queue
async void button1_Click()
{ var diggTask = GetDiggAsync();
async Task<string> GetDiggAsync()
{ var web = new WebClient();
var downTask = web.DownTaskAsync("http://digg.com");
var rss = await downTask;
var digg = await diggTask;
var digg = XElement.Parse(rss).<story>.<description>;
return digg;
}
textBox1.Text = digg;
}
IOCP
thread
UI
thread
Click
[2/12] Invoke some functions; get back “downTask” from the API
async void button1_Click()
{ var diggTask = GetDiggAsync();
async Task<string> GetDiggAsync()
{ var web = new WebClient();
var downTask = web.DownTaskAsync("http://digg.com");
var rss = await downTask;
downTask
var digg = await diggTask;
var digg = XElement.Parse(rss).<story>.<description>;
return digg;
}
textBox1.Text = digg;
}
IOCP
thread
UI
thread
Click
[3/12] “await downTask” assigns a continuation and returns diggTask
async void button1_Click()
{ var diggTask = GetDiggAsync();
async Task<string> GetDiggAsync()
{ var web = new WebClient();
var downTask = web.DownTaskAsync("http://digg.com");
var rss = await downTask;
diggTask
downTask » sc.Post{Κ1}
var digg = await diggTask;
Κ1:
var digg = XElement.Parse(rss).<story>.<description>;
return digg;
}
textBox1.Text = digg;
}
IOCP
thread
UI
thread
Click
[4/12] “await diggTask” assigns a continuation and returns
async void button1_Click()
{ var diggTask = GetDiggAsync();
async Task<string> GetDiggAsync()
{ var web = new WebClient();
var downTask = web.DownTaskAsync("http://digg.com");
var rss = await downTask;
diggTask » sc.Post{Κ2}
downTask » sc.Post{Κ1}
var digg = await diggTask;
Κ1:
var digg = XElement.Parse(rss).<story>.<description>;
return digg;
}
Κ2:
textBox1.Text = digg;
}
IOCP
thread
UI
thread
Click
[5/12] Network packet arrives with data
IOCP
thread
async void button1_Click()
{ var diggTask = GetDiggAsync();
async Task<string> GetDiggAsync()
{ var web = new WebClient();
var downTask = web.DownTaskAsync("http://digg.com");
var rss = await downTask;
diggTask » sc.Post{Κ2}
downTask » sc.Post{Κ1}
var digg = await diggTask;
rss
Κ1:
var digg = XElement.Parse(rss).<story>.<description>;
return digg;
}
Κ2:
textBox1.Text = digg;
}
UI
thread
Click
[6/12] Invoke downTask’s continuation with that data
IOCP
thread
async void button1_Click()
{ var diggTask = GetDiggAsync();
async Task<string> GetDiggAsync()
{ var web = new WebClient();
var downTask = web.DownTaskAsync("http://digg.com");
var rss = await downTask;
diggTask » sc.Post{Κ2}
downTask » sc.Post{Κ1}
var digg = await diggTask;
sc.Post{Κ1(rss)}
Κ1:
var digg = XElement.Parse(rss).<story>.<description>;
return digg;
}
Κ2:
textBox1.Text = digg;
}
rss
UI
thread
Click
[7/12] Continuation is a “Post”, i.e. addition to the UI queue
IOCP
thread
async void button1_Click()
{ var diggTask = GetDiggAsync();
async Task<string> GetDiggAsync()
{ var web = new WebClient();
var downTask = web.DownTaskAsync("http://digg.com");
var rss = await downTask;
diggTask » sc.Post{Κ2}
var digg = await diggTask;
sc.Post{Κ1(rss)}
Κ1:
var digg = XElement.Parse(rss).<story>.<description>;
K1(rss)
return digg;
}
Κ2:
textBox1.Text = digg;
}
rss
UI
thread
Click
[8/12] UI thread executes K1, giving a result to the “await”
IOCP
thread
async void button1_Click()
{ var diggTask = GetDiggAsync();
async Task<string> GetDiggAsync()
{ var web = new WebClient();
var downTask = web.DownTaskAsync("http://digg.com");
var rss = await downTask;
diggTask » sc.Post{Κ2}
var digg = await diggTask;
sc.Post{Κ1(rss)}
Κ1:
var digg = XElement.Parse(rss).<story>.<description>;
K1(rss)
return digg;
}
Κ2:
textBox1.Text = digg;
}
rss
UI
thread
Click
[9/12] “Return story” will signal completion of task
IOCP
thread
async void button1_Click()
{ var diggTask = GetDiggAsync();
async Task<string> GetDiggAsync()
{ var web = new WebClient();
var downTask = web.DownTaskAsync("http://digg.com");
var rss = await downTask;
diggTask » sc.Post{Κ2}
var digg = await diggTask;
sc.Post{Κ1(rss)}
Κ1:
var digg = XElement.Parse(rss).<story>.<description>;
K1(rss)
return digg;
}
Κ2:
textBox1.Text = digg;
}
rss
UI
thread
Click
[10/12] Invoke diggTask’s continuation with data (by posting to UI queue)
IOCP
thread
async void button1_Click()
{ var diggTask = GetDiggAsync();
async Task<string> GetDiggAsync()
{ var web = new WebClient();
var downTask = web.DownTaskAsync("http://digg.com");
var rss = await downTask;
diggTask » sc.Post{Κ2}
var digg = await diggTask;
sc.Post{Κ1(rss)}
Κ1:
var digg = XElement.Parse(rss).<story>.<description>;
K1(rss)
return digg;
}
K2(story)
Κ2:
textBox1.Text = digg;
}
sc.Post(Κ2(story))
rss
UI
thread
Click
[11/12] Return from handling the K1 continuation
IOCP
thread
async void button1_Click()
{ var diggTask = GetDiggAsync();
async Task<string> GetDiggAsync()
{ var web = new WebClient();
var downTask = web.DownTaskAsync("http://digg.com");
var rss = await downTask;
var digg = await diggTask;
sc.Post{Κ1(rss)}
Κ1:
var digg = XElement.Parse(rss).<story>.<description>;
K1(rss)
return digg;
}
K2(story)
Κ2:
textBox1.Text = digg;
}
sc.Post(Κ2(story))
rss
UI
thread
Click
[12/12] UI thread executes K2, giving a result to the “await”
IOCP
thread
async void button1_Click()
{ var diggTask = GetDiggAsync();
async Task<string> GetDiggAsync()
{ var web = new WebClient();
var downTask = web.DownTaskAsync("http://digg.com");
var rss = await downTask;
var digg = await diggTask;
sc.Post{Κ1(rss)}
Κ1:
var digg = XElement.Parse(rss).<story>.<description>;
K1(rss)
return digg;
}
K2(story)
Κ2:
textBox1.Text = digg;
}
sc.Post(Κ2(story))
rss
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.
Async:
big picture

2004: Asynchronous javascript
(AJAX) hits big-time

2008: Silverlight2:
all its lengthy APIs are async

2010: [Feb] Windows Phone 7:
all its lengthy APIs are async
Async:
big picture

2004: Asynchronous javascript
(AJAX) hits big-time

2008: Silverlight2:
all its lengthy APIs are async

2010: [Feb] Windows Phone 7:
all its lengthy APIs are async
Async:
big picture

2004: Asynchronous javascript
(AJAX) hits big-time

2008: Silverlight2:
all its lengthy APIs are async

2010: [Feb] Windows Phone 7:
all its lengthy APIs are async
Async:
big picture

2004: Asynchronous javascript
(AJAX) hits big-time

2008: Silverlight2:
all its lengthy APIs are async

2010: [Feb] Windows Phone 7:
all its lengthy APIs are async
async Task DoWorkAsync() {
try {
string[] vidUrls = await ScrapeYoutubeAsync(url);
Task<Video> t1 = DownloadVideoAsync(vidUrls(0));
Task<Video> t2 = DownloadVideoAsync(vidUrls(1));
Video[] vids = await TaskEx.WhenAll(t1, t2);
Video v = await MashupVideosAsync(vids(0), vids(1));
await v.SaveAsync(textbox1.Text);
}
catch (WebException ex) {
ReportError(ex);
}
}
// Network-bound
// Start 2 downloads
// Wait for both
// CPU-bound
// IO-bound
TASK UNIFIES ALL THESE AREAS; ASYNC TIES THEM TOGETHER
Use Async Functions to compose other tasks, for the “orchestration” of your app
Async
CallerInfo
Roslyn
Async
CallerInfo
CallerInfo
Roslyn
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);
}
Demo: CallerInfo
Async
CallerInfo
Roslyn
Async
CallerInfo
Roslyn
Roslyn
is about opening up the internals of the compiler
to let everyone use the VB/C# languages
in powerful ways.
Async
CallerInfo
Roslyn
Roslyn
is about opening up the internals of the compiler
to let everyone use the VB/C# languages
in powerful ways.
Symbols
Parser
Binder
Metaimp
IL emit
Syntax tree
API
Symbol
API
Bind/flow
API
Emit
API
Binder
IL emit
Symbols
Parser
Metaimp
Colorizer
Formatter
Outlining
NavigateTo
ObjBrowser
GoToDef
ExtractMeth
QuickInfo
Rename
FindAllRefs
Intellisense
Syntax tree
API
Symbol
API
Bind/flow
API
Emit
API
Binder
IL emit
EnC
Symbols
Parser
Metaimp
GoToDef
Interactive “REPL”
window
ExtractMeth
QuickInfo
Script files (think .vbs)
-- .csx .vbx
Colorizer
Rename
Formatter
NavigateTo
FindAllRefs
Use C#/VB
as scripting languages
for your appEnC
Outlining
ObjBrowser
Intellisense
Syntax tree
API
Symbol
API
Bind/flow
API
Emit
API
Binder
IL emit
Symbols
Parser
Metaimp
Demo: Roslyn
Async
CallerInfo
Roslyn
Async
Async
CallerInfo
• Download the Async CTP
http://msdn.com/async
• Start making Task-returning APIs today
CallerInfo
• Wait patiently…
Roslyn
Roslyn
• Download the Roslyn CTP
http://msdn.com/roslyn
• Give us feedback
Module Module1
Sub Main()
Dim robots = {"Number5", "Asimo", "Cylon"}
A parting word
from VB:
Dim xml =
<html>
ITERATOR
<head>
LAMBDAS!
<title>Robot Status</title>
</head>
<body>
<ul>
<%= Iterator Function()
For Each r In robots
Yield <li>Robot <%= r %> reporting for duty</li>
Next
End Function() %>
</ul>
</body>
</html>
Console.WriteLine(xml)
End Sub
End Module