public void DisposeGateway(IDataGateway dataGateway) { lock (slotLockObject) { var containsGateway = dataGatewaysHash.ContainsKey(Thread.CurrentThread.ManagedThreadId); if (containsGateway) { dataGatewaysHash[Thread.CurrentThread.ManagedThreadId].Dispose(); dataGatewaysHash.Remove(Thread.CurrentThread.ManagedThreadId); } if (dataGateway != null && !dataGateway.IsDisposed) { dataGateway.Dispose(); } } }