Task scheduler stops running C# console application periodically - c#

I have a task scheduler which runs a C# console application every minute. It runs the .application file via a .bat file and does so successfully for a period of time before stopping completely.
Un-installing/re-installing my console application doesn't fix the problem and the task scheduler is showing the batch file as succesfully executing. Also, running the program manually works just fine.
My questions are:
How can I get this task to run again via the task scheduler. I have tried deleting and re-creating the task, uninstalling/reinstalling the applcation.
I have a scheduled backup task occuring around the time the application stops working. Volume shadow copy is not enabled. Could this be impacting my application and why?

In the task scheduler take a look at the Settings tab. You will find an option "If the task fails, restart every".
By default (this is not checked) then if your task fails it will not be run again. You can check your task history to see if it has failed. In any case it sounds like you want to be run again even if it failed the last time it ran.
This is the option you want to change.

Despite the help, I did not manage to isolate the cause of this problem.
I have re-developed my scheduler using Quartz.NET and it's now running as a Windows service.

Related

Console Application running in Task Scheduler without stop

I've created a C# console application that does some updates in a SQL server database. I've set that application in the Task Scheduler to run daily. The application is running fine, but I noticed that the task never stops but keeps showing "Running", I have to click "End" by myself to stop it.
How can I let the task stop by itself without forcing it to stop ?
The task would stop by it self under normal conditions.
What purpose does your application server? It's doing something to keep it alive, since a normal console application would just run its course and shut down.
You always have the options of just straight up murdering it at the end of it's job, but it would be a better choice to identify what is keeping it alive.
System.Environment.Exit(0);
Is it multithreaded? Do you have some backgroundworkers running or anything?
This has been solved by using the files created in Debug instead of Release in the scheduled task, but i'm not sure why is that.

Running .net exe file using task scheduler issue

I have a C# program that I need to run on a scheduled basis. The program will initially load the web browser control and do some task. I have tried running the program by itself and it works well. But it will not run when called by a task scheduler job. This is my only scheduled task that requires a GUI to run. Is there a workaround to do this?
For you to do this you have to set up the task scheduler to "Run Only When User is logged on"
See picture:
[]1[]
More details on my blog on how to do this.

Windows Task Scheduler and sdf Database

I have a relatively simple C# application which grabs some data from a website and writes it into an sdf database file.
The application itself works just fine - however if i run the application as a scheduled task with the windows task scheduler it does not add anything to the database (it still shows up as running in the task manager, as intended).
So just to clarify it again:
Manually starting the exe works just fine (click or command window), but starting it as a task (no matter if scheduled or manually) it runs but does not add anything to the database.
What differences are there between starting an exe manually compared to a task which has a "start program" action?
Sadly this is not really the perfect answer for the question, but I have now got it working by using an SQL Server (MS-SQL 2014 Express).
Apparently .sdf files and the windows task scheduler aren't best friends.

Windows 2008 R2 Standard scheduled task stopped working - Last run result 0x2

I have been scratching my head over this for a few days and can't get to the bottom of it.
I have a scheduled task that runs a batch file every morning. The batch file starts a windows service which calls a web service on another server which then performs various tasks after which the service is stopped.
This has been working without issue for the last few months, but starting last week, every morning the scheduled task is triggered at the appointed time, but it's not starting the service and the Last Run Result is 0x2.
I've tried just about everything I could think of, checked 'Run whether user is logged in or not', 'Run with highest privileges'. I've turned on History for scheduled tasks and everything seems to run fine. There are no errors in Event Viewer nor is the service throwing any exceptions. Running the batch file manually executes just fine.
In the end I deleted and recreated the scheduled task which resolved the issue. Today this error started occurring again. I've been unable to get solid info on what exactly 0x2 means. Does any one have any more information on what could be the cause of this issue?
I've come to believe that the issue lies with the server and not the service. I exported the service from Task Scheduler and imported again with no changes and it's been running fine over the weekend. Apparently some server maintenance was carried out around the time that the issue started occurring so will investigate further with our server management department
0x2 result means that the file could not be found.
Make sure that when the Task starts (which is apparently the case), the batch file exists and is accessible.
See System errors code here on MSDN.
As explained here 0x2 could also mean "Access denied". So maybe you are facing a permission issue.
You can try to configure the Scheduled Task to Run with highest privileges in the Properties dialog of the task (General tab).

How do I restart an ASP.NET application immediately after running IISRESET?

I have windows task which restarts IIS at midnight 00:00. In my application there is a background thread which runs a global refresh at around 02:00.
My problem is that the application starts only on the first request from a browser. This may not occur for quite some time and the global refresh can be late in starting.
Is there any way to start the application without first browsing to the web application?
Ideally you should keep maintenance tasks such as this separate from your web application (either as a scheduled task or Windows service).
But, if you really need to do it this way could create a batch file that does:
iisreset /restart
"C:\Program Files\GnuWin32\bin\wget.exe" -O nul http://www.myapp.com/default.aspx
Then run this batch file as your scheduled task at 12:00. This will restart IIS and warm up your application.
You can get GNU wget.exe from:
WGET for Windows (SourceForge)
You can have another task that accesses your web site after IIS is restarted.
Still, I can't see why would you have a thread doing maintenance inside your IIS worker process. If the process dies from some reason (for example - because of the recycling configuration in the web site's application pool) the work won't get done. It's better to do this from a separate process, such as windows service or a scheduled windows task.
You shouldn't have any threads scheduled inside an IIS web application - becasue IIS has some logic to recycle the worker process and your application when it is not used. Its better to run it as a separate application (scheduled separately).
You could also use a Powershell script called by task manager. Here is simple six-line script we use to "warm up" SharePoint servers.
You could repurpose or find a similar script for a basic .NET application.

Categories

Resources