简体   繁体   中英

How do I write an async wrapper around a third party IO library in C#

I need to use a library that provides access to its own database. Unfortunately, all methods are classic synchronous. I'd prefer to have async methods to offload the IO load like we already have for say SQL Server.

I understand this is a very generic question without much concrete information. Are there any means to move to that point or is it just too bad?

Examples and/or links would be much appreciated.

If there's some form of asynchronous API in the library you are using you can use it to manufacture async API with TaskCompletionSource<T> . It can be BeginX / EndX , DoX with a XCompleted event or any other form.

If nothing like that exists, you simply can't create truly asynchronous overloads . You can offload these synchronous calls to a ThreadPool thread using Task.Run but that would only help with responsiveness and not with performance in any way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM