public static void Dispatch(int to, RiniAction task) { if (to == (int)ThreadType.ThreadPool) { ThreadPool.QueueUserWorkItem(_ => task()); } else if (to == (int)ThreadType.MainThread) { taskQueue.Enqueue(task); } else { throw new ArgumentException("invalid to"); } }
public static void DispatchAffinity(int to, RiniAction task) { if (to == (int)ThreadType.ThreadPool) { if (Thread.CurrentThread.IsThreadPoolThread) { task(); return; } } else if (to == (int)ThreadType.MainThread) { if (Thread.CurrentThread.ManagedThreadId == mainThreadId) { task(); return; } } Dispatch(to, task); }