private void workerthread() { int lastgen = (int)CurrentProject.BestYet.Generation; DateTime started = DateTime.Now; FastBitmap imagebitmap = new FastBitmap(CurrentProject.SourceImage.Width, CurrentProject.SourceImage.Height, PixelFormat.Format24bppRgb); List <JobCompare> jobs = new List <JobCompare>(); JQMessageQueue results = new JQMessageQueue(); for (int i = 0; i < CurrentProject.Properties.ThreadLimit; i++) { JobCompare job = new JobCompare(); job.Input = new JQMessageQueue(); job.Output = results; jobs.Add(job); MsgCommand msg = new MsgCommand(null, MsgCommandCommands.Init); msg.Best = CurrentProject.BestYet; msg.BestComparison = CurrentProject.BestComparison; msg.Entropy = rd; msg.Img = CurrentProject.SourceImage.Duplicate(); msg.Properties = CurrentProject.Properties; job.Input.Enqueue(msg); control.ScheduleJob(job); } while (!stopthread) { results.Trigger.WaitOne(100); while (results.Count > 0) { MsgCommand msg = (MsgCommand)results.Dequeue(); switch (msg.Command) { case MsgCommandCommands.SaveBestYet: lastiterations++; if (msg.BestComparison < CurrentProject.BestComparison) { ACpG.Update(CurrentProject.BestComparison - msg.BestComparison); AIpG.Update((int)(lastiterations - CurrentProject.BestYet.Iterations)); lastjobbest = jobs.IndexOf((JobCompare)msg.Job); CurrentProject.BestYet = msg.Best; CurrentProject.BestComparison = msg.BestComparison; CurrentProject.Changed = true; CurrentProject.BestYet.Generation++; CurrentProject.BestYet.Iterations = lastiterations; } break; } } TimeSpan sofar = DateTime.Now - started; if (sofar.TotalMilliseconds > 1000) { CurrentProject.BestYet.DrawToFastBitmap(imagebitmap); DisplayImageBitmap(imagebitmap); changed = true; started = DateTime.Now; BroadcastBestYet(jobs); Gps.Update((int)CurrentProject.BestYet.Generation - lastgen); lastgen = (int)CurrentProject.BestYet.Generation; GC.Collect(); } } foreach (JQJob job in jobs) { MsgCommand msgot = new MsgCommand(null, MsgCommandCommands.Stop); job.Input.Enqueue(msgot); } stopthread = false; }