In order to get some solid base understanding about asynchronous programming and the await
, I would like to know what the difference is between these two code snippets when it comes to multi threading and the execution sequence and time:
This:
public Task CloseApp()
{
return Task.Run(
()=>{
// save database
// turn off some lights
// shutdown application
});
}
Versus this:
public async Task CloseApp()
{
await Task.Run(
()=>{
// save database
// turn off some lights
// shutdown application
});
}
if I am calling it in this routine:
private async void closeButtonTask()
{
// Some Task 1
// ..
await CloseApp();
// Some Task 2
// ..
}