I'd like to create and manage a Windows Service application without "help" from Visual Studio's designer.
Since this is .NET, and judging by MSDN and what the designer does, this means inheriting from Installer
, and constructing and dealing with ServiceProcessInstaller
and ServiceInstaller
to be able to manage the install-time execution of the serivce.
Runtime, this means creating a ServiceBase
subclass and starting it from Main
using ServiceBase.Run
(and overriding various ServiceBase
event handling methods).
However, when I do this, Visual studio insists on treating the Installer
and ServiceBase
subclasses as designer-edited files. This doesn't exactly help readability, not to mention the fact that it generally can't deal with handwritten code at all. I'd like to avoid the designer to keep things manageable (to avoid nebulous who-knows-what-runs-when, particularly for code that's tricky to test and debug such as windows services that after all must be installed to be run at all), and also to be able to specify the service name at run-time, rather than at compile time - the designer doesn't support that.
How can I create a windows service application without all the gunk?
Windows Services cannot start additional applications because they are not running in the context of any particular user. Unlike regular Windows applications, services are now run in an isolated session and are prohibited from interacting with a user or the desktop.
Definition of Windows Services Unlike regular software that is launched by the end user and only runs when the user is logged on, Windows Services can start without user intervention and may continue to run long after the user has logged off.
ServiceBase
is derived from Component
. To disable the designer view you can attach the attribute like so:
[System.ComponentModel.DesignerCategory("Code")]
public class MyService : ServiceBase
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With