-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathWinService.cs
More file actions
91 lines (80 loc) · 1.91 KB
/
WinService.cs
File metadata and controls
91 lines (80 loc) · 1.91 KB
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
86
87
88
89
90
91
namespace WinService
{
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;
class WinService : ServiceBase
{
private Worker worker;
private Thread workerThread;
#region Component Designer generated code
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.ServiceName = "WinService";
}
#endregion
public WinService()
{
#if TRACE
Logger.WriteMessage(LogLevel.Trace, "WinService.cTor");
#endif
InitializeComponent();
worker = new Worker();
workerThread = new Thread(new ThreadStart(worker.Start));
workerThread.Name = "Worker Thread";
}
protected override void OnStart(string[] args)
{
#if TRACE
Logger.WriteMessage(LogLevel.Trace, "WinService.OnStart");
#endif
if (workerThread != null && !workerThread.IsAlive)
{
workerThread.Start();
}
}
protected override void OnStop()
{
#if TRACE
Logger.WriteMessage(LogLevel.Trace, "WinService.OnStop");
#endif
if (workerThread != null && workerThread.IsAlive)
{
worker.Stop();
workerThread.Abort();
}
}
internal void Start(string[] args)
{
#if TRACE
Logger.WriteMessage(LogLevel.Trace, "WinService.Start");
#endif
this.OnStart(args);
}
}
}