Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing code on a schedule

Status
Not open for further replies.

DatabaseDude

Programmer
Nov 7, 2005
112
US
There's some code I'd like to be executed every x number of seconds.

The only way my web host says it can be done is by putting it in an aspx (or ASP or CFM) page, and they can add it to Windows scheduled tasks. While this is an option, they schedule it to run far less frequently than I'd prefer.

I read that a web service would not be an option, as it would have to be called by an external process. (If that's incorrect, I'll gladly take correction!)

Are there any other options? (has to stay hosted with the same provider)

Thanks in advance!

 
Not that I know of

Unless you get them to run a service on the server which I highly doubt

[sub]____________ signature below ______________
You are a amateur developer until you realize all your code sucks.
Jeff Atwood[/sub]
 
I can think of one way to force a loop although it's not very elegant and I don't know what performance impact it will have. You could have a single page that you used to start off the request, and then manually visit this page via your browser. In the Application_BeginRequest event in your global.asax file, look for any requests to this page and then start an infinate loop whilst adding a sleep call e.g.
Code:
    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application startup
        If HttpContext.Current.Request.Url.PathAndQuery.IndexOf("myprocesspage.aspx") <> -1 Then
            If Application("ProcessStarted") Is Nothing Then
                Application("ProcessStarted") = True
                While 1 = 1
                    ' Do your processing here and set the sleep to your x seconds
                    System.Threading.Thread.Sleep(2000)
                End While
            End If     
        End If
    End Sub
When you visit the page, the loop will start but you'll notice that the page doesn't actually send a response back to you so it will look like the request is just hanging but it will have actually started.

I don't particularly like the solution as it's not very elegant and it goes against how web applications are designed so personally, I wouldn't use it. However, it does appear to work but at what cost you would have to check for yourself.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top