|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionOne of the most basic facts when developing applications under Windows is that as long as a program is running, its DLLs and executable cannot be overwritten. Probably you've experienced this behaviour. You want to replace a DLL with an updated version and Windows tells you, "The process cannot access the file because it is being used by another process." A look at the taskbar shows that in fact the application the DLL belongs to is still running. While developing a desktop application, this usually isn't a big problem - you modify the code, rebuild and start debugging. When the code has to be modified, you simply shut down your application, perform the code changes and restart the application (or use edit and continue in the cases where this is supported). Now if you don't develop a desktop application but a Windows Service, things usually tend to become a little clumsy, since you don't start and stop your service in the same way you start and stop a desktop application. Project Setup
For this article, I've set up a simple solution where the service is used to publish a .NET remoting server. First ApproachI guess the most common approach is to install the service directly from the Debug directory. Once the service has been installed, you can start it via the service control panel. Everything is fine up to now, but when you have to modify your code (the service implementation, for example) the shortcomings of this approach become visible: rebuilding the So you have to switch to the services control panel again, stop the service, go back to Visual Studio, rebuild again, go back to the control panel and restart the service. Honestly, I've followed this tedious manual pattern for quite a long time without giving it a second thought. But finally I asked myself, "Can't I simplify this whole procedure?" Making It EasierThe solution turned out to be amazingly simple. The much underrated pre-build action comes to the rescue: I want the service to be stopped before rebuild and to be started once the rebuild is complete.
Services can be started and stopped with two simple commands from the command line: Applying Final PolishSo now the service is being stopped automatically before the DLLs are being replaced and restarted automatically once the rebuild has been successful. Unfortunately,
ConclusionBy adding two simple lines to your build events you can simplify the process of developing a Windows service application. As an alternative for using History
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||