How to use async/await with a library that uses an event-based asynchronous pattern?
问题 I use a library that has an asynchronous method called DoWork(...) that will raise a WorkDone event when the operation completes. I would like to write a method that calls this library, but instead of maintaining the same pattern I would like my method to be async so it can be called with await . In essence, what I am trying to do is: public async Task<Result> SomeMethod() { var result = new Task<Result>(); library.WorkDone += (data) => { result.Result = data; } library.DoWork(); return await