Synchronous Code vs Async-Wrapper

I understand that Wrapping a block of code onto a Task.Run is never the answer. But what happen if you can't turn the block of synchronous code into asynchronous code because of any reason (api limitation, no access to source code of a library…)?

In my case, the library that i am using for the project does not provide any async method and they don't provide any source codes for the library. While their synchronous method is efficient on small input, i have seen deadlocks on multiple occasions, which is never a good thing on a consumer-orientated application.

So i am really attempted to just wrap the damn thing on Task.Run and call it a day, but i also fully aware of the potential penalty that comes with it.

So how do you guys normally handle this case in the real-world?

by AMRAAM_Missiles via /r/csharp

Leave a Reply