Auto Run ASP.NET pages

  • Thread starter Thread starter Khurram Hanif
  • Start date Start date
K

Khurram Hanif

I want to auto run asp.net page after a fixed interval of time without
sending any request from browser to server. I dont want to use windows
service or something like that.
 
I want to auto run asp.net page after a fixed interval of time without
sending any request from browser to server. I dont want to use windows
service or something like that.

AFAIK there isn't an easy way to launch a page or keep a site alive...

However, Paul Wilson does have an artice on how to extend the globalbase
class to reload the page automatically to keep an ASP.NET application
alive. You might be able to modify it for your purpose:

http://authors.aspalliance.com/PaulWilson/Articles/?id=12
 
Ha! I think I just answered you under another name on the
asp.net forums, but here's a copy in case you're someone else:

Not that *I* know of. Web (including asp.net) pages are
"dumb" and only respond to requests.

The first dirty solution that comes to mind is setting up a
small console app to run as a scheduled job...in it you
could use a HttpWebRequest object to invisibly fire a
request to the page so it would run.

However, that might be a cosmic waste of time when you
could have just placed the code you needed to run within
the console application, that's probably your best bet and
easiest solution.

I have no idea what your requirements are so I'm just
shooting in the dark here.

-v
 
Try using System.Timer inside of Application.Start in global.asax. It can
trigger a new thread in defined intervals. Maybe enough for you, but aware
that this would be running under aspnet working thread and corresponding
privildges.
 
I've made a test using the Timer Component and it work *almost* fine.

The code on the Enabled event is like this:
System.IO.TextWriter writer = new
System.IO.StreamWriter("d:/tmp/global_timer.log", true);
writer.WriteLine(String.Format("Log time: {0:F}", DateTime.Now));
writer.Flush();
writer.Close();

However the log is being appended twice.
Here's a chunk of the log:

App Started at Friday, January 21, 2005 12:55:56 AM
Log time: Friday, January 21, 2005 12:56:56 AM
Log time: Friday, January 21, 2005 12:56:56 AM
Log time: Friday, January 21, 2005 12:57:56 AM
Log time: Friday, January 21, 2005 12:57:56 AM
Log time: Friday, January 21, 2005 12:58:56 AM
Log time: Friday, January 21, 2005 12:58:56 AM
Log time: Friday, January 21, 2005 12:59:56 AM
Log time: Friday, January 21, 2005 12:59:56 AM


The first line is logged on the Application.Start method, with similar code.

Regards,
Manuel.
 
BTW, I modified a little bit the Elapsed code to write two lines instead, it
seams the Elapsed event is fire twice, take a look to the log:

App Started at Friday, January 21, 2005 1:18:20 AM
Log time: Friday, January 21, 2005 1:19:19 AM
EOL
Log time: Friday, January 21, 2005 1:19:20 AM
EOL
Log time: Friday, January 21, 2005 1:20:19 AM
EOL
Log time: Friday, January 21, 2005 1:20:20 AM
EOL
Log time: Friday, January 21, 2005 1:21:19 AM
EOL
Log time: Friday, January 21, 2005 1:21:20 AM
EOL


Notice the 1 sec diff! The interval, you might have guessed, is 60 secs.

Is this a bug or something?

Regards,
Manuel.
 
Back
Top