private static void reopenReceiver(IMessageReceiver receiver, Exception exception, CancellationToken cancellationToken) { Trace.TraceWarning("Restarting event receiver which died with exception:\n{0}", exception); while (true) { try { //Allow escape on stop. if (cancellationToken.IsCancellationRequested) break; receiver.Reopen(); break; // Reopen loop. } catch (Exception reopenEx) { Trace.TraceWarning("Attempt to restarting event receiver failed with exception:\n{0}", reopenEx); Thread.Sleep(TimeSpan.FromSeconds(30)); } } }