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
Related
I am trying to make the following. I have a class that at midmight it makes a log from what happened in a SQL table and makes an excel file of it. My issue is that I was told that it is inexcusable to have this application running all day only to have it run once a day and that I should do this with a system event, but I have no idea how to do this. Help, please?
The easiest solution is to use Windows' built in Scheduled Task support to run your app. Or, if you're using Microsoft Sql Server, a scheduled Sql Agent job.
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.
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.
I need to create an Intranet website (page) which allows users to indicate a local network folder to copy to a production location. Currently this is done manually using xcopy in batch files.
What I am looking for is approaches on triggering the copy so it's done in the middle of the night and an approach to copy the files. I suppose I can run xcopy from my application, but is this a good way to do this? Should I use System.IO name space objects to copy the files? Is there a better way all together?
The application will be written in C# and ASP.NET. We currently use .NET 2.0/3.0, but I have no issues using .NET 3.5 if it contains better libraries for the solution.
Basically a user will indicate which network folder they need copied along with some other business information. The folder indicated and all sub-folders need to be copied to target location (not set by user).
If there is already an application out there which does this, I am not opposed to that either. I have no need to write stuff that already exists.
For the first problem (copying at midnight), I suggest setting up a scheduled task that runs the already existing batch file (or any program, for that matter)
For the scheduling part you could use Quartz.NET
It won't be difficult to write an xcopy operation in C# using System.IO. In fact, this would give you the greatest degree of flexibility.
I think you should consider using Windows Powershell to do your copying (or another scripting language if you prefer), driven by Windows Scheduled Tasks. Though you could write an application to do this, I think it would be much more maintainable to have a script that others could edit.
The simplest solution would be to wrap your xcopy commands in a command file and schedule it to run whenever you want as a Scheduled Task on your web server.
If you want to get fancy, you can write up a web interface to the task scheduler - I'm pretty sure I've seen open source examples of that type of application too.
you've tagged this ASP but if you aren't fussy I'd recommend a combination of Windows builtin Scheduled Tasks and rsync. If it really has to be automated from an intranet page (and you're in IE) then some form of ActiveX or downloadable script/application would be needed to configure the schedule.