简体   繁体   中英

Run ASPX page for every 15 secs

I need to call an ASPX page every 15 seconds. That page will receive data through the request and update a table in the database.

I have below a sample table for auction data.

--------------------------------------------------------------
AID           STARTDATE               ENDDATE
-------------------------------------------------------------
1             18-7-2013 12:00 PM     20-7-2013 12:00 PM
2             19-7-2013 12:00 PM     21-7-2013 12:00 PM
3             19-7-2013 01:00 PM     21-7-2013 12:00 PM
4             19-7-2013 01:00 PM     22-7-2013 12:00 PM

We need to check in our database and send a web request for all records which are presently in auction mode (the current date and time between the STARTDATE and ENDDATE ). Sometimes 3 or 4 items will start their auction at same time. How do we handle this scenario?

What is the best way to get an update every 15 seconds for all items which are currently in running auction mode and store in our database?

Thank you in advance...

If you simple need to automatically reload your ASPX page every 15 seconds, just add a meta tag to page header:

<head>
<meta http-equiv="refresh" content="15">
</head>

You can use Quartz.NET Scheduling Framework for .NET Platform which is like Windows Task Scheduler but a lot better.

Project site: http://www.quartz-scheduler.net/

Nuget package: http://nuget.org/packages/Quartz/

As a client-side solution, you can use the JavaScript setInterval() function, like this:

var ResInterval = window.setInterval('myAjaxCall()', 15000); // 15 seconds
var myAjaxCall = function() {
    $.ajax({
        type: "GET",
        url: 'YourPage.aspx/MyMethod',
        dataType: "json",
        success: function(xml) {
            // Put logic here when data comes back from server
        }
};

Note: The url can be whatever is script callable (web service, WCF service, ASP.NET AJAX Page Method , etc.).

To stop the interval, do this:

window.clearInterval(resInterval);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM