27 ms·
Unfortunately the solution is very nuanced and boils down to being knowledgeable enough to know when Task.Result won't cause a deadlock, which is outside the sc
by Salgat 2y ago
Unfortunately the solution is very nuanced and boils down to being knowledgeable enough to know when Task.Result won't cause a deadlock, which is outside the scope of this guideline.
- Salgat 2y agoNot sure why the downvotes, .Result is avoided because it causes deadlocks, so you have to only use it when you are certain it won't create a deadlock condition. The most common way is to ensure it is already awaited (which defeats the point), however you can also use "var result = Task.Run(() => myTask).Result which will work without deadlocks since you're putting it on the threadpool but you lose the thread context so it won't work for UI tasks. It's not about trying to "undo" what the language developers created, but rather about you need to already be an expert if you want to avoid using await on async methods, which means you wouldn't need to be reading these guidelines in the first place.