Created
August 6, 2010 01:11
-
-
Save TravisTheTechie/510671 to your computer and use it in GitHub Desktop.
Revisions
-
TravisTheTechie created this gist
Aug 6, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ namespace Stuff { using System; using System.IO; using System.Timers; using log4net.Config; using Topshelf; using Topshelf.Configuration; using Topshelf.Configuration.Dsl; internal class Program { static void Main(string[] args) { XmlConfigurator.ConfigureAndWatch(new FileInfo(".\\log4net.config")); RunConfiguration cfg = RunnerConfigurator.New(x => { x.AfterStoppingTheHost(h => { Console.WriteLine("Custome AfterStop called invoked, services are stopping"); }); x.ConfigureService<TownCrier>(s => { s.Named("tc"); s.HowToBuildService(name=> new TownCrier()); s.WhenStarted(tc => tc.Start()); s.WhenStopped(tc => tc.Stop()); }); x.RunAsLocalSystem(); x.SetDescription("Sample Topshelf Host"); x.SetDisplayName("Stuff"); x.SetServiceName("stuff"); }); Runner.Host(cfg, args); } } public class TownCrier { readonly Timer _timer; public TownCrier() { _timer = new Timer(1000) {AutoReset = true}; _timer.Elapsed += (sender, eventArgs) => Console.WriteLine(DateTime.Now); } public void Start() { _timer.Start(); } public void Stop() { _timer.Stop(); } } }