I'm trying to get a good grasp of async/await and I want to clear some of the confusion. Can someone please explain what would be the difference in terms of execution for the following:
// version 1
public Task Copy(string source, string destination) {
return Task.Run(() => File.Copy(source, destination));
}
public async Task Test() {
await Copy("test", "test2");
// do other stuff
}
And:
// version 2
public async Task Copy(string source, string destination) {
await Task.Run(() => File.Copy(source, destination));
}
public async Task Test() {
await Copy("test", "test2");
// ...
}
Are they resulting in the same code and why would I write one over the other ?