/// <summary>
 /// Add a new path-finding job to the queue of the system
 /// </summary>
 /// <param name="job">job to enqueue</param>
 public void AddJob(PathFindingJob job)
 {
     lock (jobQ)
     {
         jobQ.Enqueue(job);
     }
 }
 protected void RunSystemMainloop()
 {
     while (isRunning)
     {
         PathFindingJob job = null;
         lock (jobQ)
         {
             if (jobQ.Count > 0)
             {
                 job = jobQ.Dequeue();
             }
         }
         if (job != null)
         {
             job.Result = aStar.Search(new System.Drawing.Point((int)Math.Round(job.From.X), (int)Math.Round(job.From.Y)),
                                       new System.Drawing.Point((int)Math.Round(job.To.X), (int)Math.Round(job.To.Y)), levelBg);
             job.Callback(job);
         }
         else
         {
             Thread.Sleep(20);
         }
     }
 }