void ThreadStart()
        {
            LongTask task = null;

            while (true)
            {
                lock (instanceLock)
                {
                    if (task != null)
                    {
                        runningTasks.Remove(task);
                        task = null;
                    }
                    if (highTasks.First != null)
                    {
                        task = highTasks.First.Value;
                        highTasks.RemoveFirst();
                    }
                    else if (normalTasks.First != null)
                    {
                        task = normalTasks.First.Value;
                        normalTasks.RemoveFirst();
                    }
                    else if (lowTasks.First != null)
                    {
                        task = lowTasks.First.Value;
                        lowTasks.RemoveFirst();
                    }
                    else
                    {
                        Monitor.Wait(instanceLock);
                    }
                    if (task != null)
                    {
                        runningTasks.AddLast(task);
                    }
                }
                if (task != null)
                {
                    task.Run();
                }
            }
        }
 public void Start(LongTask task)
 {
     lock (instanceLock)
     {
         if (task.Priority == LongTaskPriority.Low)
         {
             lowTasks.AddLast(task);
         }
         else if (task.Priority == LongTaskPriority.Normal)
         {
             normalTasks.AddLast(task);
         }
         else if (task.Priority == LongTaskPriority.High)
         {
             highTasks.AddLast(task);
         }
         Monitor.PulseAll(instanceLock);
     }
 }