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.
Related
I have a long running loop that kicks off in my web app on IIS running my C# code. I'm in development mode, so I'm attaching to the W3P3 process often, testing my loop, troubleshooting, etc.. and when I kill my interactive session in Visual Studio the loop keeps running. This is expected. What is not expected, is that after I kill the current running W3P3 process, the loop continues to perform. I have tested this many times and I just can't quite figure out how to kill the loop (kill the process, which process?).
I have no intent of coding, "is client still connected", because it is the correct behavior to continue to run, whether or not the client is connected or not, however in development mode I need to be able to kill it.
Which process is persisting and running the loop?
I am developing a Windows Service Application for sending bulk emails to the customers. In my case, I need to manually start and stop the service from the ASP.Net MVC web application passing some parameters.
Since this is on demand and there is no schedule for this activity, I want the service to perform a long-running task (Sending bulk emails to 100K customers) only once, once started and then stop itself once completed.
Is this approach correct?
If yes, how I could track its progress in MVC application?
Thank You,
This approach is incorrect. A "Windows Service" is a kind of application that waits for some client to call it, or an event to happen. (It is called daemon in Unix/Linux jargon)
In your case, "the service" should be an ordinary program that does batch processing. So, just start a separate process with Process.Start(). It doesn't block anything in your ASP.NET MVC application, it just does its job and terminate.
There are two ways to track the progress. You can call Process objects methods like WaitFor() with a timeout to see if it completes its job. Also, your "service" application would probably write its progress into a file, and the MVC application can read it anytime to see what's happening.
If I start a thread in the Application_Startup event of my web application in ASP .NET and it contains an infinite loop doing some background work using sleep methods too, will it continue running forever, assuming no exceptions occur?
Short answer: Yes
I have the same in my Application to do some cleanup work.
EDIT:
But Jani is also right: If the App is shut down the thread also stops, but if you have requests to keep the App alive (or configure the App under IIS/Mono that way - see HERE) it will run.
.No, because IIS may shutdown your AppDomain if no request comes in for a period of time.
In shared hosting environments you can not change the appdomain settings but you have access to server it can be done by changing the default time.
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.
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.