Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# console application stays on status running in task scheduler windows 2016

I made a simple c# .net console application. It's a backup script to copy a file to another folder and add the date to the the filename to keep it unique. The script runs perfectly.

However when I schedule it in Windows task scheduler, its status will stay on "running" after started while the application closed already.

I tried ending the main function with an int return value of 0 and I tried to have "System.Environment.Exit(0);" as last line of the application. I also removed all other code just leaving the exit code on to make sure the error was not in my code.

The checkbox "If the running task does not end when requested, force it to stop" is enabled.

All this didn't solve the problem.

I'm running windows server 2016

Anyone know how I can solve this problem?

like image 991
Mark Baijens Avatar asked Sep 16 '25 13:09

Mark Baijens


2 Answers

According to this discussion on TechNet, it may help to wrap your exe in a batch file.

In my experience however, the Task Scheduler view must be actively refreshed, for example by pressing F5. This workaround is also the solution for a similar question on SuperUser.

like image 65
helb Avatar answered Sep 18 '25 10:09

helb


Probably there is a problem in your application. You can try to hunt down the issue like this:

  1. Create a completely new empty console application.
  2. Create a new Task in the Task scheduler. Do not setup any triggers, options etc. Just add the action to run the console application.
  3. Test it out - it should work without any problem.
  4. Step by step add new features and then test.
  5. Once you encounter a problem, you know what is causing it.

I did 1-3 on Windows 10 and it is working like expected.

like image 21
Dávid Molnár Avatar answered Sep 18 '25 08:09

Dávid Molnár