예제 #1
0
        private void StartUpdate()
        {
            DateTime lastframe = DateTime.Now;
            Graphics draw      = null;

            Logger.LogMessage("Starting update loop");

            double fixedwait = (1000 / FPS); // number of msec to wait assuming zero time to draw frame

            while (this.run)
            {
                TimeSpan elapsed = DateTime.Now.Subtract(lastframe);

                double wait = fixedwait - elapsed.TotalMilliseconds;
                if (wait > 0)
                {
                    System.Threading.Thread.Sleep((int)fixedwait);
                }

                if (Glass == null)
                {
                    System.Threading.Thread.Sleep(1000);
                }

                if (Glass != null)
                {
                    if (Glass.Follow != null && Glass.Follow.HasExited)
                    {
                        Logger.LogMessage(String.Format("{0} has exited. quitting.", Glass.Follow.ProcessName));
                        System.Environment.Exit(0);
                    }

                    if (draw == null)
                    {
                        draw = Glass.CreateGraphics();
                        draw.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
                    }

                    if (Graphics == null)
                    {
                        Thread.Sleep(500);
                        continue;
                    }
                    IntPtr activeWindow = GetForegroundWindow();

                    bool foreground = activeWindow == Glass.Follow.MainWindowHandle;

                    // if there is nothing to draw, do a big sleep
                    if (Graphics.Values.Count == 0 || !foreground)
                    {
                        Clear(draw);
                        Thread.Sleep(1000);
                    }
                    if (foreground)
                    {
                        lock (Graphics)
                        {
                            Draw(draw);
                        }
                        Glass.FollowWindow();
                    }
                    lastframe = DateTime.Now;
                }
            }
        }