Created
August 6, 2010 01:11
-
-
Save TravisTheTechie/510671 to your computer and use it in GitHub Desktop.
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 characters
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment