Пример #1
0
        public Form1()
        {
            dat               = new CSData();
            CSSearch          = new System.Timers.Timer(1000);
            CSSearch.Elapsed += (sender, e) =>
            {
                WorkRestartEvent.Set();
            };

            var frameSync = Task.Run(() =>
            {
                while (true)
                {
                    finishWait.Reset();
                    var pid = FindCaveStory();
                    handle  = OpenCaveStory(pid);

                    if (handle == 0)
                    {
                        goto wait;
                    }
                    var ptls = GetTls(handle, pid);
                    while (!finishedFlag && (isAlive(handle) != 0))
                    {
                        UInt32 tid, opt;
                        if (WaitFrame(handle, out pid, out tid, out opt))
                        {
                            GetCSData(handle, dat, ptls);
                            datLoaded = true;
                            if (frameDelay > 0)
                            {
                                Thread.Sleep(frameDelay);
                            }
                            ContinueFrame(pid, tid);
                            Screen.Invalidate();
                        }
                        else
                        {
                            continue;
                        }
                    }
                    Detach(handle, pid);

                    wait:
                    datLoaded = false;
                    Screen.Invalidate();
                    WorkRestartEvent.Reset();
                    finishWait.Set();
                    WorkRestartEvent.WaitOne();
                    if (finishedFlag)
                    {
                        return;
                    }
                }
            });

            CSSearch.Start();
            InitializeComponent();
        }
Пример #2
0
 private void Form1_FormClosed(object sender, FormClosingEventArgs e)
 {
     finishedFlag = true;
     finishWait.WaitOne();
     WorkRestartEvent.Set();
 }