M
mick
private async void btnTest_Click_1(object sender, RoutedEventArgs e)
{
await Task.Factory.StartNew(async () => {
var x = await GetInt();
MessageBox.Show("recieved int " + x.ToString());
});
MessageBox.Show("Finished");
}
private async Task<int> GetInt()
{
return await Task.Factory.StartNew( () => {
System.Threading.Thread.Sleep(5000);
return 999;
});
}
Been messing around with the new async stuff and I've come accross this oddity -
Shouldn't the MessageBox.Show("Finished"); line run only after the awaited Task
above it
has finished? In other words shouldn't it be that Tasks continuation. As it is
the
"Finished" MessageBox is showing straight away. Can someone explain what I'm
missing.
TIA,
mick
{
await Task.Factory.StartNew(async () => {
var x = await GetInt();
MessageBox.Show("recieved int " + x.ToString());
});
MessageBox.Show("Finished");
}
private async Task<int> GetInt()
{
return await Task.Factory.StartNew( () => {
System.Threading.Thread.Sleep(5000);
return 999;
});
}
Been messing around with the new async stuff and I've come accross this oddity -
Shouldn't the MessageBox.Show("Finished"); line run only after the awaited Task
above it
has finished? In other words shouldn't it be that Tasks continuation. As it is
the
"Finished" MessageBox is showing straight away. Can someone explain what I'm
missing.
TIA,
mick