public void DoDelegatedWork() { List <Action> local = null; lock (DelegatedWork) { if (DelegatedWork.Count > 0) { local = new List <Action>(DelegatedWork); DelegatedWork.Clear(); } } if (local != null) { foreach (Action action in local) { action.Invoke(); } } }
private void DelegateWork(Action action) { lock (DelegatedWork) { DelegatedWork.Add(action); } }