0

I am speaking specifically of a service as opposed to an application.

Environment.Exit(0) and Stop() both give a message box saying they were stopped unexpectedly (even if there's no actual error given).

The goal is to start a service on startup (it must be a service, not an app), have it perform a small task, and then exit. It should simply exit cleanly without a message box.

Ross
  • 33
  • 3
  • Let all threads finish..? – dan1st Feb 27 '20 at 16:46
  • Does this answer your question? [Can a service written in .NET self-terminate?](https://stackoverflow.com/questions/554276/can-a-service-written-in-net-self-terminate/554292) – canton7 Feb 27 '20 at 16:46
  • @dan1st This is a Windows Service – canton7 Feb 27 '20 at 16:46
  • https://stackoverflow.com/questions/53837763/how-to-make-a-windows-service-from-net-core-2-1-2-2 – Sir Rufo Feb 27 '20 at 16:48
  • Will it have started threads if I call Stop() in OnStart without doing anything else? The posts linked seem to also tell me to just call Stop(), but I get the message saying it has started and stopped in a message box. I tried putting stop in a task with a delay, but still get the message. – Ross Feb 27 '20 at 17:14
  • OK, ignore me. It was actually the fact that it was indeed just too close to startup. My delayed task was only a 1 second delay too. If I change it to a 30 second delay Stop then works without complaint. – Ross Feb 27 '20 at 17:31

0 Answers0