i have full access to server i want to run C# code on server automatically and every minute it should repeat. Is there any techniques or web services allow allow asp.net project regarding same?
I cant able to find correct reference. Post a link here if possible. I have ready code that allows my work on Page_Load. But I want to make such like , whole code should be Running every 5 minutes.
RFID #Attendance #RealTime
Similar question to what you have asked.
Best way to run scheduled tasks
All of my tasks (which need to be scheduled) for a website are kept
within the website and called from a special page. I then wrote a
simple Windows service which calls this page every so often. Once the
page runs it returns a value. If I know there is more work to be done,
I run the page again, right away, otherwise I run it in a little
while. This has worked really well for me and keeps all my task logic
with the web code. Before writing the simple Windows service, I used
Windows scheduler to call the page every x minutes.
Another convenient way to run this is to use a monitoring service like
Pingdom. Point their http check to the page which runs your service
code. Have the page return results which then can be used to trigger
Pingdom to send alert messages when something isn't right.
You have many options:
1- put the code in a web service, and create a consumer windows service to invoke it every N minutes.
2- put your code in a windows service and execute it from a timer.
3- Make a thread in the web-page (Not recommended) to execute your code.
Hope that helps you
Related
I have a classified web application developed with ASP.NET MVC and I need to implement a advert bump up option.
As a example if someone use this option (for 3 days) today at 10.15 AM, advert should bump up each day 10.15 AM for 3 days.
So I need a scheduler to execute some code to bring up the advert to top of the list.
Can someone explain me how approach this inside my ASP.NET MVC application or using any other 3rd party resource?
save on the database every time the user click on the option. and every time he clicks on the option check if he has click in the pass two days.
You will need to use a task scheduler service. It is not possible to create a scheduled task in ASP.NET MVC, because it simply listens and responds to HTTP requests. You could put your code to bump up the advert in an ASP.NET MVC controller, but you would still need something to send an HTTP request to trigger the controller at the given time. So there's probably not a great reason to put that code in a controller under most circumstances.
It is easy to set up scheduled tasks in most cloud computing environments. For example, in AWS you could write a Lambda function in C# and schedule it with a CloudWatch Events rule.
If your application is running on a Windows Server, the most robust way to implement a task scheduler would probably be to write a Windows Service application to call the task logic on a polling loop. It is also possible to create a console application and trigger it with the Windows Task Scheduler. This approach is quicker and easier to get up and running than developing a Windows service, but in my experience is more likely to fail and quit running without your knowledge. Either way, it will be important to make sure to write good logging and error notification code.
I'm sure there are also good 3rd party tasks schedulers out there too, I just haven't used any of them. Those are just some general guidelines, but if you want more detail on them just let me know and I can post some links.
Every night my HTTPContext.Current.Cache is cleared. I want to Warm up the site during the night at time X and fill the cache with data.
Since I use HTTPContext, this has to run within the website. I am currently starting the caching by a simple button click on the site that then asynchronously fills the cache in a few minutes time frame.
I have searched for a solution where the options didn't really do the job as easily as I think it could be:
System.Timers are polling constantly. It also doesn't seem to have an option to set a specific time I want it to run?
Quartz seemed very overkill, but could probably do the job. Although a bit to read into to get it working.
RegisterWaitForSingleObject Could also work, but only a timer here as well? Also not sure if you can check if one object is already created and therefor risk of creating many of them. Nor change the timer after the object is created.
Skimmed through them relatively fast, so could be wrong. What's your take on running scheduled http request from within the site?
[EDIT] typo.
Here's what I'd do-
Create a page within the site with anonymous access, and put the code to start the caching (which is written on button click right now) ON THE PAGE LOAD event.
Create a simple console application in C#, which makes HTTPRequest to that page (You can see examples for System.Net.WebClient).
Schedule the .exe of this console application to run at certain time (like 4 AM) on Windows Scheduler on the server.
Firstly let me apologise, as I don't really know how to phrase the question.
The issue I'm having is trying to keep my database 'alive' while users come to my site. An example being, if I build my c# asp.net application and publish it, then try and navigate to it, it takes a while to respond (which I get, I understand it, this isn't an issue for me) the problem is if some person hasn't been to the site for a while, it seems to take a while again, like a session timer has passed, I'm not sure if this is something to do with App Pool recycling?
I've tried to run a scheduled task to hit the database (trying to keep it responsive) every 15 minutes, but this doesn't seem to work, it works well every 15 minutes for say 5 hours, and then I receive a message on a random call that the request has taken over 4 seconds to respond and therefore fails.
My question then, how do I keep my connection to the database / the site responsive so that each time a person requests it, the site loads quickly, rather than having to 'start up'
Kind regards as always
I suggest to increase connection pool size in your connection string.
This looks like what you want:
Keep an ASP.NET IIS website responsive when time between visits is long: Keep an ASP.NET IIS website responsive when time between visits is long
You might consider IIS application auto-start?
Some web applications need to load large amounts of data, or perform expensive initialization processing, before they are ready to process requests. Developers using ASP.NET today often do this work using the “Application_Start” event handler within the Global.asax file of an application (which fires the first time a request executes). They then either devise custom scripts to send fake requests to the application to periodically “wake it up” and execute this code before a customer hits it, or simply cause the unfortunate first customer that accesses the application to wait while this logic finishes before processing the request (which can lead to a long delay for them).
ASP.NET 4 ships with a new feature called “auto-start” that better addresses this scenario, and is available when ASP.NET 4 runs on IIS 7.5
I am building a Intranet application using ASP/C# to perform a specific job. However I have two requirements
I would like to be able to call the webpage from a browser and have a form to allow the user to run the service manually.
However I also need a scheduled task to be ran twice a day that calls the webpage and runs the service automatically 'onvisit' (without the need for a form submission)
I could easily meet requirement 1 OR 2. But I want to meet both conditions.
Note: We cannot create a separate .EXE file that runs the needed code.Also, only as a final choice would I want to make two separate webpages.
Parametrize the service and put the params in the querystring so when you call it from the exe it behave as expected.
I have a clockIn & clockOut module that records start time & end time for workers from an Asp.NET app.
I want to ask how to do cron job for asp.net application to see if a worker has not entered their time on that date or week and send an email notification to remind them to enter start time and end time.
ASP.NET is the wrong tool for the job. You would be better off either writing a Console Application that is run on a scheduled task, or a Windows Service that polls on a regular interval. ASP.NET is purely meant for a request/response model.
Either one can access whatever data store the website is reading from/writing to just as easily as the ASP.NET site can.
If you've done neither, the Console Application is by far the simplest to write and implement. Windows Services aren't all that bad, but involve extra overhead, including difficulty debugging, and the need to go through a special installation process as compared to the XCOPY deployment model possible with Console applications.
If you REALLY want to do it in ASP.NET, you can write an asp.net web page that does this, and use the Windows Scheduled Task to run it. The Scheduled Task can open up Internet Explorer to a specific page just as easily as it can run any executable. But I wouldn't recommend it. You'll forever have to close the IE window when the task is finished, and it's just really a "hackish" solution. I did it back when I was a pure web developer and didn't know any better, but not since.
Jeff Atwood posted on the Stack Overflow blog, titled as Easy Background Tasks in ASP.NET, in the early days of this site about a simple way to do background tasks in ASP.NET. If your tasks are relatively lightweight, this might not be a bad way. If you have a reason to really want to keep everything inside an existing ASP.NET app, this might be the way to go.
The gist:
At startup, add an item to the HttpRuntime.Cache with a fixed expiration.
When cache item expires, do your work, such as WebRequest or what have you.
Re-add the item to the cache with a fixed expiration.
Although its not technically a cron job, from within a website you can get the website to call a set page at X time of the day.
I have done this a few times via a web method call, which is called on the timer from the application start.
Basic explanation is here:
Call a webpage from c# in code