0

I keep getting this error:

Error 1061: The service cannot accept control messages at this time

This happens when I attempt to stop the service installed using InstallUtil from this location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe

I am attempting to debug the windows service in question. My problem is that everytime I attempt to introduce changes to the codebase, the computer "A physical machine - Dell Precision T3500" requires that I restart the entire machine to completely uninstall the service, before I do a reinstall.

I have looked at this Link and it is not helpful in my scenario as I would first have to stop the service to be able to gain full access to the location where my build is generated to.

Whilst the service is attempting to restart before I do the restart of PC, when I attempt to build the service from my code, I get this interesting error from the compiler:

Error 16 Unable to copy file "obj\x86\Debug\X_WindowsService.exe" to "bin\x86\Debug\X_WindowsService.exe". The process cannot access the file 'bin\x86\Debug\X_WindowsService.exe' because it is being used by another process. X_WindowsService

Because of the error above I also think this is why I am not able to use the SO solution from here.

Does anyone have a clever idea for me to go through to bypass having to restart the machine as I debug and make changes to my codebase?

I also had a look at this link from SO but it has no marked solution, I also tried one of the Microsoft forums for a solution but it too has no applicable solution as they recommend the restart which I am trying to avert.

Community
  • 1
  • 1
Sizons
  • 640
  • 2
  • 8
  • 24
  • IIRC, the most common cause for error 1061 in .NET services is an OnStart() function that doesn't exit. – Harry Johnston Jun 07 '16 at 21:47
  • All I do in the OnStart() method is some error logging stuff to a physical file location and then I open up and start the thread as such: _thread = new Thread(new ThreadStart(X_Start)); _thread.Start(); Is there anything else I should be doing in there to optimise the service? – Sizons Jun 08 '16 at 13:16
  • Have you checked that `.CanStop` is set to true? – Harry Johnston Jun 08 '16 at 21:12

1 Answers1

0

I feel so silly after finding this solution. I should most certainly have used the KISS principle for this one.

Turns out, all I had to do was look for the service's process from task manager and simply end the task. After that a refresh to my services list shows the service status as blank, meaning it has completely stopped without a restart of the machine.

Sizons
  • 640
  • 2
  • 8
  • 24