/** * Must be called in a finally handler when done with the loop */ public void Dispose() { if (Thread.CurrentThread != ourThread) { throw new InvalidOperationException("Not in the correct thread"); } Thread value; failedSessionThreads.TryRemove(ourThread, out value); client.removeParentWatcher(watcher); }