Skip to content

Avoid calling Task.Result and Task.Run #46

@nathan-alden-sr

Description

@nathan-alden-sr

It is well known that one should never call Task.Result, Task.Wait(), or Task.WaitAll() in normal code due to the possibility of deadlocks. I see a couple of places where you are calling the Task.Result property. You should rewrite those places like this: someTask.ConfigureAwait(false).GetAwaiter().GetResult(). This is the idiomatic way to run a task when inside a method that is not asynchronous.

There is also no need to call Task.Run unless you intend to either await the call or to fire-and-forget. If you need the result and you're inside a synchronous method, you should write the code as I've done above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions