public void Publish(Event @event, bool ack = false) { new Thread(o => { try { @event = o as Event; if (ack) { int @try = 0; eventStorage.AddEvent(@event); while (@try < retryCount) { if ((@event = eventStorage.GetEvent(@event.Id)) != null) { PublishInner(@event); } else { return; } Thread.Sleep(5000); } logger.LogCritical($"Failed to publish event after {retryCount} tries"); } else { PublishInner(@event); } } catch (Exception e) { logger.LogCritical($"Failed to publish event, {e}"); } }).Start(@event); }