Ejemplo n.º 1
0
 private void TryExecuteTask(PriorityTaskBase task)
 {
     try
     {
         using (Profiler.CurrentProfiler.Begin("Running Task"))
         {
             task.Run();
         }
     }
     catch (Exception e)
     {
         // ignored
         Debug.Write(e);
     }
 }
Ejemplo n.º 2
0
        protected void QueueTask(PriorityTaskBase task)
        {
            try
            {
                task.UpdatePriority(_lastPlayerPosition);

                lock (_tasks)
                {
                    _tasks[(int)task.PriorityClass].Add(task);
                    _awaitTasks.Set();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Oops! " + e);
            }
        }
Ejemplo n.º 3
0
 private IEnumerable <PriorityTaskBase> GetNextTask()
 {
     while (true)
     {
         PriorityTaskBase task = null;
         using (Profiler.CurrentProfiler.Begin("Awaiting Tasks"))
         {
             try
             {
                 _awaitTasks.WaitOne();
                 lock (_tasks)
                 {
                     for (int i = 0; i < _tasks.Length; i++)
                     {
                         var list = _tasks[i];
                         if (list.Count > 0)
                         {
                             int minIndex    = -1;
                             int minPriority = -1;
                             for (int j = 0; j < list.Count; j++)
                             {
                                 var t = list[j];
                                 int p = t.Priority;
                                 if (p < minPriority || task == null)
                                 {
                                     minIndex    = j;
                                     task        = t;
                                     minPriority = p;
                                 }
                             }
                             if (task != null)
                             {
                                 if (minIndex != list.Count - 1)
                                 {
                                     list[minIndex] = list[list.Count - 1];
                                 }
                                 list.RemoveAt(list.Count - 1);
                                 break;
                             }
                         }
                     }
                     if (_tasks.Sum(t => t.Count) > 0)
                     {
                         _awaitTasks.Set();
                     }
                 }
             }
             catch (ObjectDisposedException)
             {
                 yield break;
             }
             catch (AbandonedMutexException)
             {
                 yield break;
             }
         }
         if (task != null)
         {
             yield return(task);
         }
     }
 }