/// <summary>
        /// Send an Action Delegate to be run on the main thread. See EditorDispatchActions for some common usecases.
        /// </summary>
        /// <param name="task">An action delegate to run on the main thread</param>
        /// <returns>An AsyncDispatch that can be used to track if the dispatch has completed.</returns>
        public static AsyncDispatch Dispatch(Action task)
        {
            lock (dispatchQueue) {
                AsyncDispatch dispatch = new AsyncDispatch();

                // enqueue a new task that runs the supplied task and completes the dispatcher
                dispatchQueue.Enqueue(() => { task(); dispatch.FinishedDispatch(); });

                return(dispatch);
            }
        }
        /// <summary>
        /// Send a Coroutine to be run on the main thread. See EditorDispatchActions for some common usecases.
        /// </summary>
        /// <param name="task">A coroutine to run on the main thread</param>
        /// <param name="showUI">if the Editor Corotine runner should run a progress UI</param>
        /// <returns>An AsyncDispatch that can be used to track if the coroutine has been dispatched & completed.</returns>
        public static AsyncDispatch Dispatch(IEnumerator task, bool showUI = false)
        {
            // you need this system for this to work! https://gist.github.com/LotteMakesStuff/16b5f2fc108f9a0201950c797d53cfbf
            lock (dispatchQueue) {
                AsyncDispatch dispatch = new AsyncDispatch();

                dispatchQueue.Enqueue(() =>
                {
                    if (showUI)
                    {
                        EditorCoroutineRunner.StartCoroutineWithUI(DispatchCorotine(task, dispatch), "Dispatcher task", false);
                    }
                    else
                    {
                        EditorCoroutineRunner.StartCoroutine(task);
                    }
                });

                return(dispatch);
            }
        }
        private static IEnumerator DispatchCorotine(IEnumerator dispatched, AsyncDispatch tracker)
        {
            yield return(dispatched);

            tracker.FinishedDispatch();
        }