public void Dispose() { try { CancelAllSubscriptions(); subscriptions.Apply(sub => sub.Dispose()); } catch { // Assuming that failing on dispose, means that it is already Disposed. The channel and connection will be closed below anyway } var cleanupActions = new List <Action>(); cleanupActions.Add(() => { try { if (channel.IsValueInitialized) { channel.Value.Dispose(); } } catch { // Assuming that failing on dispose, means that it is already Disposed } }); cleanupActions.Add(() => { try { if (connection.IsValueInitialized) { connection.Value.Dispose(); } } catch { // Assuming that failing on dispose, means that it is already Disposed } }); executor.TriggerCleanupState(cleanupActions); executor.Dispose(); AppDomain.CurrentDomain.DomainUnload -= OnAppDomainUnload; }