winforms - How can I detect a Windows service at project build -


I am working on a solution that includes a Windows service and a WinForms client that contacts that service.

In my pre-build and post-build event, I have some net start and pure stop command to start and stop the service , But this happens sometime when it causes a problem (file not found, the service has already been stopped, etc.)

If a service is running or < What is a method to check if code> is set before pure start?

I like putting this exam in a .cmd file and running in a pre-build event for the project.

You do not really need to install, start and stop every time, instead of performing your service Consider adding a command-line key in the appropriate so that when it is specified, it is run as a service (which does the normal servicebase. Run), and when this key is absent, then this routine console As the application runs. You will get the added benefit of being able to dump the logger output directly into the console so that debugging is completely easy.

  if (args.GetLength (0) == 1 & amp;; & amp; amp;; Amp; digits [0]. Toupper () == "/ service") {servicebase [] services = new Servicebase [] {new MySwive ()}; ServiceBase.Run (services); } // if else {InitAndStartWhateverIs Required ToRunServer (); Console.ReadLine (); } //  

Comments