Wednesday, September 26, 2018

c# - How do I offer a synchronous version of my async method?

I have this async method in C# code:




public async Task DoYourThingAsync()
{
....
}


Now, for some legacy code I have to offer a synchronous version of this method, similar to how for example HttpClient offers synchronous and async versions of the same method. I do not want to copy-paste my code to a second method, so I did this:



public int DoYourThing()
{

return DoYourThingAsync().Result;
}


Question: is this the correct way to accomplish this?

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...