adding missing dx headers
[reactos.git] / irc / TechBot / TechBot / TechBotService.cs
1 using System;
2 using System.Threading;
3 using System.Collections;
4 using System.ComponentModel;
5 using System.Data;
6 using System.Diagnostics;
7 using System.ServiceProcess;
8 using System.Configuration.Install;
9
10 namespace TechBot
11 {
12 public class TechBotService : System.ServiceProcess.ServiceBase
13 {
14 private Thread thread;
15 private ServiceThread threadWorker;
16
17 public TechBotService()
18 {
19 InitializeComponents();
20 }
21
22 private void InitializeComponents()
23 {
24 this.ServiceName = "TechBot";
25 }
26
27 /// <summary>
28 /// This method starts the service.
29 /// </summary>
30 public static void Main()
31 {
32 System.ServiceProcess.ServiceBase.Run(new System.ServiceProcess.ServiceBase[] {
33 new TechBotService() // To run more than one service you have to add them here
34 });
35 }
36
37 /// <summary>
38 /// Clean up any resources being used.
39 /// </summary>
40 protected override void Dispose(bool disposing)
41 {
42 base.Dispose(disposing);
43 }
44
45 /// <summary>
46 /// Start this service.
47 /// </summary>
48 protected override void OnStart(string[] args)
49 {
50 try
51 {
52 threadWorker = new ServiceThread(EventLog);
53 thread = new Thread(new ThreadStart(threadWorker.Start));
54 thread.Start();
55 EventLog.WriteEntry(String.Format("TechBot service is running."));
56 }
57 catch (Exception ex)
58 {
59 EventLog.WriteEntry(String.Format("Ex. {0}", ex));
60 }
61 }
62
63 /// <summary>
64 /// Stop this service.
65 /// </summary>
66 protected override void OnStop()
67 {
68 try
69 {
70 thread.Abort();
71 thread.Join();
72 thread = null;
73 threadWorker = null;
74 EventLog.WriteEntry(String.Format("TechBot service is stopped."));
75 }
76 catch (Exception ex)
77 {
78 EventLog.WriteEntry(String.Format("Ex. {0}", ex));
79 }
80 }
81 }
82 }
83
84 [RunInstaller(true)]
85 public class ProjectInstaller : Installer
86 {
87 public ProjectInstaller()
88 {
89 ServiceProcessInstaller spi = new ServiceProcessInstaller();
90 spi.Account = ServiceAccount.LocalSystem;
91
92 ServiceInstaller si = new ServiceInstaller();
93 si.ServiceName = "TechBot";
94 si.StartType = ServiceStartMode.Automatic;
95 Installers.AddRange(new Installer[] {spi, si});
96 }
97 }