Beispiel #1
0
    public void Tick()
    {
        while (workingJobs.Count < MAX_WORKING && waitingJobs.Count > 0)
        {
            int id = waitingJobs.Dequeue();
            if (jobs.ContainsKey(id))
            {
                workingJobs.Add(id);
                jobs[id].thread.Start(jobs[id]);
            }
        }

        for (int i = 0; i < workingJobs.Count; i++)
        {
            if (jobs.ContainsKey(workingJobs[i]))
            {
                JobInfo job = jobs[workingJobs[i]];
                job.Progress();
                if (job.finished)
                {
                    workingJobs[i] = -1;
                    job.Finished();
                    job.thread.Abort();
                    jobs.Remove(job.id);
                }
            }
            else
            {
                workingJobs[i] = -1;
            }
        }

        int count = workingJobs.Count;

        for (int i = 0; i < count; i++)
        {
            if (!workingJobs.Remove(-1))
            {
                break;
            }
        }
    }