1

I use a library that have a method:

public void SendNotification(INotification notification, SendNotificationCallbackDelegate callback)

I would like to use this method like:

var result = await sender.SendNotification(...);
return result;

I would like to know if it is possible to wrap this call inside an async method that will do the internal callback wait response and then return. SendNotification is async inside ... but is based on delegate pattern.

Daniel Kelley
  • 7,579
  • 6
  • 42
  • 50
Radu D
  • 3,505
  • 9
  • 42
  • 69
  • You'll have to await an AutoResetEvent that's Set() by the callback. – Hans Passant Sep 18 '14 at 09:26
  • You'll have to wrap the call or add an extension method to `sender` e.g. `public Task SendNotificationAsync(this Whatever sender, INotification notification)` In that method you can use a TaskCompletionSource, see here: http://blog.stephencleary.com/2012/02/creating-tasks.html – RobH Sep 18 '14 at 09:53

0 Answers0