I have been trying to find out what is the difference between.
Task.Run(() => DoSomething()); and
Task.Run(async() => await DoSomething()); I have been testing this and it does not look like it affects functionality. I am really confused which one to use if you want to run a task. I am calling awaitable task is this just a syntax sugar or is there a difference between those. Which one I should use and why? I am really curious because even if I store that task in a variable it still returns a Task for both cases.
and also we have asynchronous method
private async Task DoSomething() { //do something here } I found a great post here await Task.Run vs await explaining specific case of awaiting an async method in the event handler of a GUI application, but that explains only the difference between this
await Task.Run(async () => await LongProcessAsync()); and this
await LongProcessAsync();
Task.Run(DoSomething);is fine, asDoSomethingwill be implicitly converted to aFunc<Task>as with the lambda.await Task.Run(DoSomething).Taskreturned fromTask.Run. This example shows the warning, even when a lambda is used.