3 * Copyright (C)2007-2008 Versabanq Innovations Inc. and contributors.
4 * See the included file named LICENSE for license information.
8 using System
.Collections
;
9 using System
.ComponentModel
;
10 using System
.ServiceProcess
;
11 using System
.Configuration
.Install
;
19 public static class SillyHelper
21 public static void print(this Stream stream
, string s
)
23 byte[] utf8
= s
.ToUTF8();
24 stream
.Write(utf8
, 0, utf8
.Length
);
30 public class ProjectInstaller
: Installer
32 ServiceProcessInstaller spi
;
35 public ProjectInstaller()
37 si
= new ServiceInstaller();
38 si
.ServiceName
= "ServTest";
39 si
.Description
= "Description++";
40 si
.StartType
= ServiceStartMode
.Automatic
;
42 spi
= new ServiceProcessInstaller();
43 spi
.Account
= ServiceAccount
.LocalSystem
;
52 public class ServTest
: ServiceBase
60 f
= File
.Open("/tmp/test.txt",
63 FileShare
.ReadWrite
| FileShare
.Delete
);
66 t
.Elapsed
+= new ElapsedEventHandler(t_Elapsed
);
68 ServiceName
= "ServTest";
71 static void Main(string[] args
)
73 ServTest o
= new ServTest();
74 o
.f
.print(String
.Format("args: ({0}) ({1}) {2}\n",
76 Environment
.UserInteractive
,
79 if (Environment
.UserInteractive
80 || (args
.Length
> 0 && args
[0] == "-f"))
82 Console
.WriteLine("Running in foreground!");
89 Console
.WriteLine("Running in background!");
94 protected override void OnStart(string[] args
)
96 f
.print("Service started.\n");
100 protected override void OnStop()
103 f
.print("Service stopped.\n");
106 private void t_Elapsed(object sender
, ElapsedEventArgs e
)
108 f
.print("Timer elapsed! " + (++i
).ToString() + "\n");