Skip to content

Instantly share code, notes, and snippets.

@zapthedingbat
Created October 28, 2014 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zapthedingbat/914623c6f0aebacdd526 to your computer and use it in GitHub Desktop.
Save zapthedingbat/914623c6f0aebacdd526 to your computer and use it in GitHub Desktop.
Timeout calls to IBus.Send().Register()
// NOTE: There is a bug in NServiceBus where registered callbacks that are not invoked remain in a static dictionary.
var asyncResult = _bus.Send(message).Register(ar => { }, null);
if (!asyncResult.AsyncWaitHandle.WaitOne(_timeout))
{
// Signal the async result so callback threads don't remain blocked
((EventWaitHandle)asyncResult.AsyncWaitHandle).Set();
throw new OperationCanceledException();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment