Re:Open Source .NET libraries that make your life easier
by tonyedgecombe on Friday April 10, 2015 @10:42AM
(#9354624)
TopShelf looks interesting, I have written quite a few Windows services over the years and there have always been lots of gaps in the MS offering.
[ Parent
| on HN ]
Re:Open Source .NET libraries that make your life easier
by sixothree on Friday April 10, 2015 @01:46PM
(#9355920)
I've been using TopShelf in production settings for a few years now and have been more than pleased. We have yet to discover any issues related to using the library. And new developers find it extremely easy to pick up.
Re:Open Source .NET libraries that make your life easier
by wooUK on Friday April 10, 2015 @10:49AM
(#9354680)
I've just rolled out a service using TopShelf having not used it previously. It really does simplify things. The best bit for me is being able to just hit F5 and having the thing run as a console application. No need to manually attach to processes for debugging.
Re:Open Source .NET libraries that make your life easier
by chiph on Friday April 10, 2015 @11:25AM
(#9354934)
This technique lets you debug your service as if it were a console app - just pass in -a on the command line.
In your Main method:
if (args.Length > 0 && args[0] == "-a")
{
// Running as an application
MyService ms = new MyService();
ms.DoStart();
Console.WriteLine("Press Enter to Stop");
Console.ReadLine();
ms.DoStop();
} else {
// Running as a service
ServiceBase[] servicesToRun = { new MyService() };
ServiceBase.Run(servicesToRun);
}
And in the MyService class that derives from ServiceBase: protected override void OnStart(string[] args)
{
DoStart();
}
protected override void OnStop()
{
DoStop();
}
internal void DoStart()
{
// Start your service thread here
}
internal void DoStop()
{
// Tell your service thread to stop here
}
Re:Open Source .NET libraries that make your life easier
by iaskwhy on Friday April 10, 2015 @11:52AM
(#9355113)
I use something similar to debug a WCF project:
private static void Main()
{
var serviceHandler = new ServiceHandler();
if (Environment.UserInteractive)
{
serviceHandler.OnStart(null);
Console.WriteLine("Service started! Press <ENTER> to terminate service.");
Console.ReadLine();
serviceHandler.OnStop();
Console.WriteLine("Service stopped!");
return;
}
Run(serviceHandler);
}
Re:Open Source .NET libraries that make your life easier
by talles on Friday April 10, 2015 @12:11PM
(#9355248)
I normally use this (simple) technique: http://stackoverflow.com/a/126016
Re:Open Source .NET libraries that make your life easier
by junto on Friday April 10, 2015 @11:00AM
(#9354762)
Once you use TopShelf you'll never go back! Honestly, debugging Windows Services are simple using TS.
Re:Open Source .NET libraries that make your life easier
by breischl on Friday April 10, 2015 @01:34PM
(#9355848)
It's definitely superior to hand rolling Windows services. We have something like 6 or 7 TopShelf-based services, a couple of which are self-hosted WebAPI endpoints. No problems or gotchas that I can remember, aside from slightly marginal documentation last time I looked.
Re:Open Source .NET libraries that make your life easier
by legomaster on Friday April 10, 2015 @02:33PM
(#9356232)
Topshelf's documentation does need some more TLC -- if there's something specific you thought was lacking I can take a look at updating it.
I'm glad to hear you're getting value out of it! Last place I was at, we had about 30 distinct services running. It was a huge bonus to have Topshelf.
Re:Open Source .NET libraries that make your life easier
by breischl on Friday April 10, 2015 @03:58PM
(#9356779)
I think my problem was using the Custom Service style, rather than inheriting from ServiceControl. There are a number of ways to interact with the HostConfiguration.Service<T>() method and its overloads, but there's only one tiny section in the documentation.
TBH, I think you might want to deprecate that whole way of using TopShelf. Using ServiceControl is much much easier and better documented. I think if one wants to keep TopShelf out of their core code, it's easier to create a separate "ServiceWrapper" project that has a ServiceControl subclass and calls into your other code, rather than using the HostControl.Service() style.