Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Service vs Windows Application - Best Practice

When should I go for a Windows Service and when should I go for a "Background Application" that runs in the notification area?

If I'm not wrong, my design decision would be, any app that needs to be running before the user logins to the computer should be a service. For everything else use a background app. Is my decision right?

Moreover, if I need "admin privileges" for my background app, I would escalate using a manifest. Are there any other specific advantage of running as a service?

like image 302
Mugunth Avatar asked Jun 16 '09 07:06

Mugunth


People also ask

What is the difference between a Windows application and a Windows Service?

User Interface – Unlike regular applications, Windows Services do not have a user interface; they run in the background and the user does not directly interact with them. A Windows Service does not stop when a user logs off the computer; a regular application will.

When should you use Windows services?

You should create a Windows Service to run code in the background, without user interaction. For example, a Windows Service will run even if no-one is logged on. Any server that accepts connections (such as a mail, web, or FTP server) should usually be a Windows Service.

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.

What is a Windows Service application?

What Does Windows Service Mean? A Windows service is an application that usually serves a core operating system function running in the background and has no user interface.


Video Answer


2 Answers

My general rules of thumb are as follows

  • If it needs to always run, it's a service.
  • If it needs to be run under a particular user account, Network Service, Local System, generally it's a service (or a COM+ application)
  • If the user needs some control over it, it's generally a notification area application.
  • If it needs to notify the user of something, it's a notification area application

The fun comes when you have the need to run something as a system account, but also interact with it. IIS is a good example of this, it's a service, but the administration is an application - it needs to be running at the startup, it needs access to particular things a user can't normal access (c:\inetpub), but the user needs to be able to start, stop and configure it.

like image 162
blowdart Avatar answered Sep 30 '22 12:09

blowdart


I would design an application as a service if the applcation has a critical purpose and should never (or rarely) be closed. Windows services provide good crash-recovery options, good notifications (see the recovery tab in service property).

Also a good reason to use services is because they can run under any user ( so if you deploy them on a server that you remote to, you can safely log out after starting the service without worring that the application will close too).

I also design services in combination with a desktop application that can interact with the service and can be used to monitor or reconfigure the service while running. This way you can have all the benefits of a tray application, in your service.

However, you should not abuse using services and only use them, as I said, for cirtical applications.

like image 40
AlexDrenea Avatar answered Sep 30 '22 10:09

AlexDrenea