Error after stopping service through Task Scheduler

0

I've a running service on Windows Server 2012 called FileWatcher. It checks files into folders and does other stuff. I have to stop and restart the service every day at 2.00 AM so i configured two scheduled tasks: the first one stops the service at 2.00 AM, the second one starts it at 2.01 AM.

Everything is working. The service stops, then it restarts. But if I check the Event Viewer I find some errors.

  • 2.00.00 AM : Service stopped successfully.
  • 2.00.00 AM : Failed to stop service. System.InvalidOperationException: An unhandled exception was detected ---> System.InvalidOperationException: Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read.
  • 2.00.00 AM : Description: The process was terminated due to an unhandled exception. Exception Info: System.InvalidOperationException
  • 2.00.00 AM : Faulting application name: FileWatcher.exe, version: 1.0.0.0, time stamp: 0x5aeae776 Faulting module name: KERNELBASE.dll, version: 6.3.9600.18340, time stamp: 0x5736541b Exception code: 0xe0434352 Fault offset: 0x00014878 Faulting process id: 0x1a6c
  • 2.01.01 AM Service Started Successfully.

What's going on? I mean, the service stops and restarts, why I get these errors? I already checked in another similar question, and the guy solved changing the project from Windows Application to Console Application. Mine was already Console App.

Thank you in advance, M.

c#
service
task
schedule
event-viewer
asked on Stack Overflow May 25, 2018 by MNeg

1 Answer

1

Can you repeat the error when you run / stop service by hand? Can you find the line, where this happens?

Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read.

This is a wild guess, but you have Console.ReadKey() somewhere in your service.

answered on Stack Overflow May 25, 2018 by Janci

User contributions licensed under CC BY-SA 3.0