Reputation: 21
I am trying to call an asynchronous method from a synchronous method.
For instance: Let methodAsync
be an asynchronous method.
static void methodSync()
{
object1.methodAsync().Wait();
object1.methodAsync().Result;
object1.methodAsync().GetAwaiter().GetResult();
}
Suggestion by sonar:
Replace this use of
Task.Wait
withawait
.
Similarly, for the Task.Result
and GetAwaiter().GetResult()
.
https://rules.sonarsource.com/csharp/RSPEC-4462
what can we do to call asynchronous method from a synchronous method?
Upvotes: 2
Views: 589