日期:2014-05-17  浏览次数:20859 次

C#CPU使用过高,求大神
 private void xianshiyanse()
        {
            int i = 0;
            RECT rect = new RECT();
            GetWindowRect(jubing, ref rect);
            KeyboardHookLib.HookStruct hookStruct = new KeyboardHookLib.HookStruct();

            tim.Interval = 1;
            tim.Tick += delegate
            {
                i++;
                if (i == 100)
                {
                    System.Threading.Thread.Sleep(50);
                    GC.Collect();
                    i = 0;
                }
                if (pictureBox1.BackgroundImage != null)
                {
                    pictureBox1.BackgroundImage.Dispose();
                }
                int x1 = rect.Left;
                int y1 = rect.Top;
                //Point P = new Point(x1, y1);
                Point P = new Point(MousePosition.X, MousePosition.Y);
                IntPtr h = GetDC(new IntPtr(0));        //指定坐标的句柄
                int c = GetPixel(h, P);//取指定点色彩
                int r = c % 256;
                int g = (c / 256) % 256;
                int b = c / 256 / 256;
                try