diff --git a/src/Messaging/NBB.Messaging.Host/Internal/MessagingHost.cs b/src/Messaging/NBB.Messaging.Host/Internal/MessagingHost.cs index b9b32eb3..0f325597 100644 --- a/src/Messaging/NBB.Messaging.Host/Internal/MessagingHost.cs +++ b/src/Messaging/NBB.Messaging.Host/Internal/MessagingHost.cs @@ -60,15 +60,17 @@ public void ScheduleRestart(TimeSpan delay = default) return; _logger.LogInformation($"Messaging host is scheduled for restart in {delay.TotalSeconds} seconds"); + + // TODO: when upgrading to .NET 8 remove the "suppressed" check since it doesn't throw any more + // https://github.com/dotnet/runtime/pull/82912 + using IDisposable _ = ExecutionContext.IsFlowSuppressed() ? null : ExecutionContext.SuppressFlow(); + Task.Run(async () => { try { await Task.Delay(delay); - if (!ExecutionContext.IsFlowSuppressed()) - ExecutionContext.SuppressFlow(); - await TryStopAsync(); await StartAsync(); }