Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Service without Visual Studio interference

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?

like image 527
Eamon Nerbonne Avatar asked Feb 09 '11 14:02

Eamon Nerbonne


People also ask

Can a Windows service launch an application?

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.

How often does a Windows service run?

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.


1 Answers

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
{

}
like image 165
Kevin Deenanauth Avatar answered Oct 04 '22 19:10

Kevin Deenanauth