-
Notifications
You must be signed in to change notification settings - Fork 1
/
MyNewService.cs
85 lines (67 loc) · 2.34 KB
/
MyNewService.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using AutomationFPP;
namespace MyNewService
{
public partial class MyNewService : ServiceBase
{
private LibraryFPP l;
private System.Diagnostics.EventLog eventLog1;
Thread childThread;
public MyNewService()
{
InitializeComponent();
eventLog1 = new System.Diagnostics.EventLog();
if (!System.Diagnostics.EventLog.SourceExists("FPP"))
{
System.Diagnostics.EventLog.CreateEventSource(
"FPP", "FPP");
}
l = new LibraryFPP();
eventLog1.Source = "Application";
eventLog1.Log = "Application";
eventLog1.WriteEntry("In OnStart of FPP");
ThreadStart childref = new ThreadStart(MyThread);
childThread = new Thread(childref);
childThread.Start();
}
protected override void OnStart(string[] args)
{
if (childThread.IsAlive) return;
eventLog1.WriteEntry("In OnStart of FPP");
ThreadStart childref = new ThreadStart(MyThread);
childThread = new Thread(childref);
childThread.Start();
}
protected override void OnStop()
{
eventLog1.WriteEntry("In OnStop of FPP(start)");
childThread.Abort();
eventLog1.WriteEntry("In OnStop of FPP (complete)");
}
private void MyTimer_Tick(object sender, EventArgs e)
{
}
private void MyThread()
{
long i = 0;
while (childThread.IsAlive)
{
i++;
eventLog1.WriteEntry("In MyThread of FPP (Start) - " + i);
l.SaveXMLtoDB2("http://weather.cyi.ac.cy/data/met/CyDoM.xml");
l.DoForecast(new DateTime().Date);
eventLog1.WriteEntry("In MyThread of FPP (Complete) - " + i);
Thread.Sleep(60000*60); //1 hour
}
}
}
}