I have to execute action once a day. It is to end users work time if they haven't done it themselves.
Users can end their time by clicking on button that execute ActionResult in Controller:
[HttpPost]
[Authorize]
public ActionResult EndWork(...)
{
...
}
How can I run action like that automatically every day at midnight? Do I have to use task scheduler or Windows Service for it? I can't set trigger on database, because records are inserted to database by EndWork().
I have a MVC 3 website.
Any help much appreciated!
You can use following :
Write a windows service which keeps a watch on your DB and performs the action.
For scheduling, please see Quartz .Net
You could schedule events using something such as Quartz.NET. You can see how you can get started here.
Can you not just use windows scheduled tasks - create an *.exe and set the task to run the exe every night at midnight? Or point the scheduled task at a bat file that kicks off a script to do what you need?
You can use a if statement. Use it with a timer so that it checks current time of the day and if it meets the condition then it executes whatever action you assign to it.
Related
I am coding in c# using filesystem watcher to check a directory.
How can I say "after 8:00 am if file X is not existing do ....." ?, this have to be verified every day.
Thanks for your help !
I don't think you need a FileSystemWatcher here. Simply use a Timer or Scheduled tasks which runs at 8:00, then check for your file exist and get the job done.
Timer can be used if your application will be running all the time throughout the day 24 x 7, otherise use latter.
FileSystemWatcher is something, that we use to get notifications about change in the file system anytime and not for checking something exist at particular time.
Update: You can use the FileSystemWatcher to get the file update immediately, then process it and also the Timer mentioned above which finds whether file hasn't been created till 8.00.
You can use a scheduler such as Quartz.Net to start at a certain time of the day, see the site for more details:
http://www.quartz-scheduler.net/
I have made a application in c# with a RavenDB.
Now i need some assistant at creating a cronjob script which runs like 3 time's a day to delete files in my database older than 15 days.
An easy couple of steps:
Write a *.bat script to do your logic
use Task Scheduler to run the script according to the desired schedule
I have used Quartz.net in the past and that contains a CronTrigger. Very flexible and well documented.
if its an app in asp.net you can call the function in App_Start function of global.aspx page using timer controls which repeat after a certain amount of time.
you can refer to this Url for more details
http://www.codeproject.com/Articles/12117/Simulate-a-Windows-Service-using-ASP-NET-to-run-sc
I have a program that loops through and XML file and performs various functions and logs its activity. I now need to add to my XML file parameters where I can specify the day of week and time that the task should be skipped... I.E., during our scheduled maintenance windows.
Basically, I still want the task to run, I just don't want it to send out an e-mail alert if something fails during the maintenance window.
Since we sometimes have more than one maintenance window, but only one time during a 24-hour period, I thought of defining my parameters like this:
<DayOfWeek>Sat, Wed</DayOfWeek>
<TimeRange>00:00-06:00</TimeRange>
What would be the best logic to handle this? Our maintenance windows should run between the same time-range no matter what day of week it is.
To make it simple, put in the app.config of your service 2 key, for SkipTaskFrom and SkipTaskTo, with the date format you prefer (http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx) and then parse it
I have an ASP.NET page that gets a list of game server ip addresses (quickly) and loops through them running a command line tool against them to get special game server information. I have to use the command line tool because I don't know how it works to get the information from the machines and I don't want to reinvent the wheel. The looping is the slow part (surprise surprise). Each command line tool run takes up to a second so with approximately 60 ip addresses polled on average, the page load can take from 30-60 seconds to render the results I need.
My obvious thought was "multithread that thing!" Well, I tried that w/ thread pools but ended up with a hanging website if more than one person accessed the page at a time. This was only using 4-5 calls at a time up to the 60 making it a 10 sec load time. So not only did it hang with multiple users, it was still too slow. I'd be happy if I could get it to under 3 seconds.
I should mention this page is in a shared hosting environment. I had a great solution before outside of the shared hosting environment but I had to cut costs and I'm trying to make it work w/ shared now.
Is there any hope?
You shouldn't really be polling these servers "on demand." It would be better to use ASP.NET to show the list of server information, and some other process - like a windows service, or scheduled task - to poll the servers every couple of minutes to generate that list. To summarize: The service would create an XML file (for example) and ASP.NET would display it to users. This way, the amount of users viewing the page does not affect the amount of times you try to poll the servers.
Update:
You need to ensure the process that pings servers is a singleton. Specifically, a singleton is a class in which only a single instance can exist. In more general terms for your case, you need to set a global flag that says "i'm currently pinging servers" and another global datetime value to says "the last time i pinged the servers was at hh:mm:ss" - you could use the Application dictionary to store the boolean flag and the datetime. Each time someone loads your page, check the flag to see if it's already pinging the servers. If it is, don't do it. If the flag says ok, then check the current time against the last time you did it. If it's less than 5 minutes, don't do it. All of this should be done in a background thread. This thread should update an xml file in App_Data. All requests to your pages should render this data immediately. A page request should never block. If the file is not there on the first call, then return "ping in progress, try again in 5 minutes." Follow?
Read about the ASP.NET Application state dictionary here:
http://msdn.microsoft.com/en-us/library/ie/ms178594.aspx
Low tech solution might be to call a bat file that makes each of the exe calls, instead of the exe repeatedly from asp.net. Saves the repeated shells to the OS overhead
Each call to the exe can pipe the results to a text file, which can then be read back all at once, once control returns to the asp.net app from the bat.
If the list of ip's change, then the the asp.net application could create the bat file before running it.
Hi want to send birthday emails to all employees which details are stored in database.
I found Quartz .NET library
but can't understand the code exactly.
can anyone please give me some sample code.?
This is the first time I heard about Quartz. It looks cool.
Found this stackoveflow thread How to use Quartz.net with ASP.NET
Further to Ives - answer:
What about from their website:
http://www.quartz-scheduler.org/docs/examples/index.html
This blog maybe of help as well..
http://blog.goyello.com/2009/09/21/how-to-use-quartz-net-in-pro-way/
Stack Overflow Question
Sending Periodic Mail according to user's Setting in ASP.net?
I guess this is something similar here.
You can code a small console application, a simple database with 1 table as you said which keeps dates,names and other details you need.
Simply select all rows which meets condition
Birthday == DateTime.Now
and mail them in a loop.
You can add this exe as a scheduled job with a few clicks and set it to run every day. It would also be a good practice for you.
You can write a script file (possibly in VBScript as a VBS file) and schedule that script file in the Windows Task Scheduler (say every morning 8 AM) on the server level.