Welcome to mirror list, hosted at ThFree Co, Russian Federation.

LiveViewForm.cs - github.com/ClusterM/hakchi2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1c2476327022e5566d94f038634b74f5a6d09b84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace com.clusterrr.hakchi_gui
{
    public partial class LiveViewForm : Form
    {
        Thread screenShotThread;

        public LiveViewForm()
        {
            InitializeComponent();
            screenShotThread = new Thread(screenShotLoop);
            screenShotThread.Start();
        }

        void screenShotLoop()
        {
            while (true)
            {
                try
                {
                    var screenshot = WorkerForm.TakeScreenshot(false);
                    Invoke(new Action(delegate ()
                    {
                        pictureBox.Image = screenshot;
                    }));
                }
                catch (ThreadAbortException)
                {
                    screenShotThread = null;
                    return;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Error: " + ex.Message + ex.StackTrace);
                    Thread.Sleep(1000);
                }
            }
        }

        private void LifeViewForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (screenShotThread != null)
                screenShotThread.Abort();
        }
    }
}