Better way of looping to detect change.

Posted by Dremation on Stack Overflow See other posts from Stack Overflow or by Dremation
Published on 2010-03-30T18:09:24Z Indexed on 2010/03/30 18:23 UTC
Read the original article Hit count: 321

Filed under:
|

As of now I'm using a while(true) method to detect changes in memory. The problem with this is it's kill the applications performance. I have a list of 30 pointers that need checked as rapidly as possible for changes, without sacrificing a huge performance loss. Anyone have ideas on this?

memScan = new Thread(ScanMem);

public static void ScanMem()
        {            
            int i = addy.Length;
            while (true)
            {
                Thread.Sleep(30000); //I do this to cut down on cpu usage
                for (int j = 0; j < i; j++)
                {
                    string[] values = addy[j].Split(new char[] { Convert.ToChar(",") });
                    //MessageBox.Show(values[2]);
                    try
                    {
                        if (Memory.Scanner.getIntFromMem(hwnd, (IntPtr)Convert.ToInt32(values[0], 16), 32).ToString() != values[1].ToString())
                        {
                            //Ok, it changed lets do our work
                            //work 
                            if (Globals.Working)
                                return;                            
                            SomeFunction("Results: " + values[2].ToString(), "Memory");
                            Globals.Working = true;
                        }//end if
                    }//end try
                    catch { }
                }//end for
            }//end while
        }//end void

© Stack Overflow or respective owner

Related posts about c#

Related posts about memory