private void ThreadFunc() { var actions = new List <ThreadItem>(); while (!m_stop) { // Swap action list pointers lock (m_lock) { var tmp = m_items; m_items = actions; actions = tmp; } // Execute all tasks in a row for (int i = 0; i < actions.Count; i++) { // Execute the action // Note, it's up to action to provide exception handling ThreadItem item = actions[i]; #if DEBUG try { #endif item.Action(item.Arg); #if DEBUG } catch (Exception ex) { Debug.LogException(ex); throw; } #endif } actions.Clear(); // Wait for next tasks m_event.WaitOne(); } }
public static void Add(ThreadItem action) { WorkItems.Add(action); }