-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
66 lines (54 loc) · 1.88 KB
/
Program.cs
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
57
58
59
60
61
62
63
64
65
66
/*
* Based on https://www.codeproject.com/articles/290013/formless-system-tray-application
*/
using System;
using System.Windows.Forms;
using System.Threading;
using NLog;
using AutoCap.Properties;
namespace AutoCap
{
static class Program
{
private static Mutex mutex = null;
private static Logger logger = LogManager.GetCurrentClassLogger();
[STAThread]
static void Main()
{
bool createdNew;
// prevent second instance from starting
mutex = new Mutex(true, "AutoCap", out createdNew);
if (!createdNew)
{
logger.Debug("Existing AutoCap already running, exiting");
return;
}
logger.Info("Starting");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// use System.Windows.Forms.Timer; executes on the UI thread
using (System.Windows.Forms.Timer AutoCapTimer = new System.Windows.Forms.Timer())
{
int minInterval = Settings.Default.CaptureMinuteInterval;
if (minInterval < 1 || minInterval > 60)
{
minInterval = 1;
}
logger.Debug("minInterval={0}", minInterval);
AutoCapTimer.Interval = (minInterval * 60 * 1000); // minInterval minutes
using (Capture AutoCapCapture = new Capture()) {
AutoCapCapture.captureScreenToFile();
AutoCapTimer.Tick += new EventHandler(AutoCapCapture.Tick);
AutoCapTimer.Start();
// Show the system tray icon.
using (ProcessIcon pi = new ProcessIcon())
{
pi.Display();
Application.Run();
}
}
}
logger.Info("Exiting");
}
}
}