How to call a completion method everytime ThreadPool.QueueUserWorkItem method is returned
问题 I am using System.Threading.ThreadPool.QueueUserWorkItem(x => MyMethod(param1, param2, param3, param4, param5)); I want to call the following method from the main thread every time the call to MyMethod is completed: UpdateGui() { } How do I do that? Thanks! 回答1: Keep a global counter of work items queued and an object to protect it: int runningTasks = 0; object locker = new object(); Every time a task is added increment the counter: lock(locker) runningTasks++; System.Threading.ThreadPool