Program that runs once a week

RTSol
RTSol used Ask the Experts™
on
Hi,

I need to write a program for a web site that allways runs once a day. My idea is to use a snipped according t the supplied code below. I know this code is stupid and will block the site - but an idea along those lines.  My question is - is this the best approach and how do I make sure that this code always is alive. What if I want this task to start running before any visits to the site has occured - how is that done? If I want the task to allways run at a specific time each day - how is that done? The site is hosted at an ISP and my access to the web server is very limited.

Best regards
RTSol
protected void Page_Load(object sender, EventArgs e)
    {
        //do other things ...
        ScheduledTask();
    }

    protected void ScheduledTask()
    {
        //Do the stuff
        Thread.Sleep(86400000); //sleep 24 hours
    }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Here is  good article on using Cache callbacks to create timer jobs in asp.net

http://www.codeproject.com/KB/aspnet/ASPNETService.aspx
Reza RadConsultant, Trainer

Commented:
you can create another page for notcorrecttime view.
and in your scheduled task try to check time of day, if it is the time you want to start doing , then do anything you want , otherwise redirect to notcorrecttime page you created.
maybe you need autorefresh on your page, because page_load will called only when a user browse on your page
hi RTSol,

If my post seems irrelevant, kindly ignore that.

As per my knowledge, you can go for a workaround other than this.
Better create a WINDOWS SERVICE and activate that using a scheduler (Scheduled Tasks).

My point is that, this will not affect the normal working of you website and will serve the purpose.

Below are some links which will guide u, How to make a windows service

http://www.c-sharpcorner.com/UploadFile/mahesh/window_service11262005045007AM/window_service.aspx
http://www.codeproject.com/KB/dotnet/simplewindowsservice.aspx
http://www.codeguru.com/vb/gen/vb_system/services/article.php/c4825/

Author

Commented:
Thanks for your tips guys. I think the link from halceyon is what I really wants. Building a service would probably be the best but my ISP will not let me install it on the web server.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial