只是检查… _count被安全地访问,对吧? 这两种方法都由多个线程访问。 private int _count; public void CheckForWork() { if (_count >= MAXIMUM) return; Interlocked.Increment(ref _count); Task t = Task.Run(() => Work()); t.ContinueWith(CompletedWorkHandler); } public void CompletedWorkHandler(Task completedTask) { Interlocked.Decrement(ref _count); // Handle errors, etc… }