Exemplo n.º 1
0
        void framer_DoWork(object sender, DoWorkEventArgs e)
        {
            Stopwatch        sw     = new Stopwatch();
            BackgroundWorker worker = (BackgroundWorker)sender;

            while (!worker.CancellationPending)
            {
                int frameTime = (int)(1000 / (double)FPS);
                int delay     = frameTime;
                sw.Start();
                if (saveImages)
                {
                    byte[] frame = null;
                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        frame = VideoControl.GetFrame((Scale / 100D), Quality);
                    }));
                    long   ticks = DateTime.Now.Ticks;
                    string name  = ticks + ".jpg";
                    worker.ReportProgress(0, new PushImage()
                    {
                        Image = frame, Name = name
                    });
                }
                sw.Reset();
                delay -= (int)sw.ElapsedMilliseconds;
                if (delay > 0)
                {
                    System.Threading.Thread.Sleep(delay);
                }
            }
        }
Exemplo n.º 2
0
        void FrameRun()
        {
            try
            {
                Stopwatch sw = new Stopwatch();
                while (running)
                {
                    int frameTime = (int)(1000 / (double)FPS);
                    int delay     = frameTime;
                    if (saveImages)
                    {
                        sw.Start();
                        byte[] frame = null;
                        this.Dispatcher.Invoke((Action)(() =>
                        {
                            frame = VideoControl.GetFrame((Scale / 100D), Quality);
                        }));
                        long ticks = (long)DateTime.Now.ToUniversalTime().Subtract(
                            new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
                            ).Ticks;
                        string name = ticks + ".jpg";
                        lock (images)
                        {
                            images.Add(new PushImage()
                            {
                                Image = frame, Name = name
                            });
                        }

                        int elapsed = (int)sw.ElapsedMilliseconds;
                        sw.Reset();
                        delay -= elapsed;
                        if (delay < 0)
                        {
                            delay = 0;
                        }
                    }
                    System.Threading.Thread.Sleep(delay);
                }
            }
            catch (ThreadInterruptedException)
            {
                //
            }
            catch (Exception ee)
            {
                MessageBox.Show("Frame: " + ee.ToString());
                running = false;
            }
        }