I know there are answers to this, but none of them are crystal clear. Is there any difference between the following?
// Option A
var result = Task.Run(() => GetAsync(id)).GetAwaiter().GetResult();
// Option B
var result = Task.Run(async () => await GetAsync(id)).GetAwaiter().GetResult();
Is one of these better or preferred?
To clarify, the reason Task.Run()
is used is that this is called from a synchronous method, one that cannot be made async. The reason it cannot be made async is that it is called from a razor view, which (in ASP.NET 4.5) is sync only. The reason Task.Run()
is used is to be certain we don't get deadlocks.
EDIT This is not a duplicate of the linked question