Maintain C # application

I am creating a Windows service that uses FileSystemWatcher and is running in the background.

I don’t want to continue uninstalling and installing the service every time I want to debug, so I would like to do most of my development in a regular program before transferring it to the service. But I'm completely new to this, and when I run it, it just goes through the block and exits.

What would be a good way to keep the program running?

0
source share
4 answers

http://einaregilsson.com/run-windows-service-as-a-console-program/

I used this before to debug my service as a console application based on whether it works in an interactive user environment.

public partial class DemoService : ServiceBase { static void Main(string[] args) { DemoService service = new DemoService(); if (Environment.UserInteractive) { service.OnStart(args); Console.WriteLine("Press any key to stop program"); Console.Read(); service.OnStop(); } else { ServiceBase.Run(service); } } 
+6
source
 while (true) { // Execute your program functionality here. } 
0
source

I wrote part 7 of the series some time ago, titled: Building a Windows Service . It covers all the intricacies of construction services, makes them friendly for debugging and self-installation.

The main feature set I was looking for was as follows:

  • Creating a service that can also be used from the console
  • Own logging of service start / close and other actions
  • Resolving multiple instances using command line arguments
  • Self-Service and Event Log Installation
  • Proper Service Exception and Error Logging
  • Manage startup, shutdown and reboot options
  • Handling custom service commands, session credentials, and events
  • Security and access control settings

The end result was a Visual Studio project template, which in one step creates a working service full of all of the above. It was a great time saver for me.

see Building a Windows Service - Part 7: Finishing Touch for a link to a project template and installation instructions.

0
source

Heres documentation from MSDN @ http://msdn.microsoft.com/en-us/library/7a50syb3(v=vs.80).aspx?ppud=4 . I have tried this before and it works in the .NET Framework 3.x. At the moment, I could not find my descriptive notes.

Use pragma #If DEBUG for debugging purposes such as console outputs. Another uses a Debug object.

If you have problems with this, say so. Perhaps I can find my notes or make a Windows Service application, just to find out if the steps work on MSDN.

0
source

Source: https://habr.com/ru/post/1432481/


All Articles