public void Dispose() { Task.WhenAll(trainBagsSemaphores.Select(q => q.WaitAsync())); piStore.Store(primaryIndex); foreach (var t in trainBags) { t.Dispose(); } foreach (var s in trainBagsSemaphores) { s.Release(); } }