public static bool QueueBackGroundTask(BackGroundTask task)
 {
     lock (s_BackGroundTaskQueue)
     {
         s_BackGroundTaskQueue.Add(task);
     }
     return(true);
 }
        static void ThreadFunction(object arg)
        {
            var id = Thread.CurrentThread.ManagedThreadId;

            while (!s_bShutdown)
            {
                int index = Convert.ToInt32(arg);
                int val   = threadTickCounts[index]++;
                val++;
                threadTickCounts[index] = val;

                Util.Log("alive " + id);
                BackGroundTask task = null;

                if (s_BackGroundTaskQueue.Count > 0)
                {
                    lock (s_BackGroundTaskQueue)
                    {
                        if (s_BackGroundTaskQueue.Count > 0)
                        {
                            task = s_BackGroundTaskQueue[0];
                            s_BackGroundTaskQueue.RemoveAt(0);
                        }
                    }
                    if (task != null)
                    {
                        if (!UpdateManager.IsPluginResetting())
                        {
                            task.Execute();
                        }
                    }
                }
                else
                {
                    Thread.Sleep(16);
                }
                if (threads == null)
                {
                    return; // play button.
                }
            }
        }