public void Run() { lock (this) { thread = Thread.CurrentThread(); } try { if (!canceled) { Action.Run(); } } finally { lock (this) { thread = null; doneEvent.Set(); completed = true; } } }