I made an OCR bot for the online game "Conquer Online".
It works fine, however, it works very slowly.
I figured an i7 should have no problem scanning 250, 000 pixels, especially when there are less than 100 instructions per pixel being executed.
Troublingly, the bot takes about 5 seconds per scan of the screen when it should take mere milliseconds.
I've inserted tons of debugging statements throughout the code, including this one:
public bool searchScreenCoord(Point screenCoord, Bitmap printscreen, List<Point> blacklistedPixels, List<LootableItem> lootableItems,
List<AttackableMonster> attackableMonsters, ClickTracker ct, bool chkGreens, bool chkBlacks, bool chkLoot)
{
Color pixel = printscreen.GetPixel(screenCoord.X, screenCoord.Y);
#if DEBUG_Time
DateTime pixelStartTime = DateTime.Now;
#endif
if (chkGreens)
{
#if DEBUG_Time
if ((DateTime.Now.Subtract(pixelStartTime).Ticks > 500))
{
File.AppendAllText("C:\\ocr\\stats\\pixelStats.csv",
"green.Checked:" + DateTime.Now.Subtract(pixelStartTime).Ticks.ToString() + "\r\n");
pixelStartTime = DateTime.Now;
}
#endif
As you can see from the definition, chkGreens is a bool passed in from the doMonsters method/thread and not a call to chkGreenMonsters.Checked which might have had problems because of accessing the GUI thread. I eliminated the repeated cross-thread calls in an attempt to solve my problem.
My debugging file contains the following:
black.Checked 10000
green.Checked 10001
green.Checked 10000
black.Checked 10000
get black word 30001
black.Checked 10001
black.Checked 10001
get black word 10001
For no reason that I can think of, the thread sleeps for 10, 000 ticks between declaring the date time and checking the passed in bool.
It doesn't happen every time searchScreenCoord is called though. Maybe once every 25 or 50 calls.
I guess this could be time slicing with a misbehaving process demanding 10, 000 ticks every so often, but that explanation seems far fetched.
Does anyone know why this is happening to me?
I'd appreciate any advice that could eliminate the dreaded 10, 000 tick naps the app is taking.
Thanks.