Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have created a page where i have attached a timer control of ajax.it has a interval of 10 sec.
the timer is working fine when i run it on local host or host it on server.
the problem is that when the website is not operative (when no one is login to that)
the timer control is not performing the schedule task.
so can any one help me how to perform this.
what i want is "my timer control should work when even no one has opened that page or website"
help me out

What I have tried:

<asp:Timer ID="Timer1" runat="server" Interval="600000" ontick="Timer1_Tick">

protected void Timer1_Tick(object sender, EventArgs e)
{
// my desired function
}
Posted
Updated 23-Aug-16 3:03am

asp.net is a request\response technology....your code runs in response to a request. What can you do if there is no request? Nothing, your code can't run. This is the problem with scheduled tasks in asp.net, there is no guarantee they will run. You can use something like quartz.net which will do a better job for you that your existing code, but it still isn't guaranteed.

What you need to do instead is use a more appropriate technology like a Windows Service or a scheduled task.
 
Share this answer
 
Comments
Shantanu sinha 23-Aug-16 9:17am    
txs for your reply.i understand the said things.i was just curious to know whether this function could be performed.and as per your solution i think there one way which is http://stackoverflow.com/questions/3243348/how-to-call-a-method-daily-at-specific-time-in-c.
You have already asked this question several times and the answer is still the same. Do not use ASP.Net for this. ASP.Net is not designed to be run on schedules. As you know, the code in ASP.Net only runs when someone hits the page and then it stops. That is how it works.

You could, although I would suggest against it, create a batch file that has the url to your page in it and schedule that batch file to run every x minutes. That will execute the code on your page every x minutes.

However, if you want something scheduled or timed or control when code runs, then use a windows console app or a windows service.
 
Share this answer
 
Comments
Shantanu sinha 23-Aug-16 9:14am    
what i asked before was another thing and this is another.
as i was not getting result as required so i asked this here.
i know that quartz.net is better option but this project is very small to use it.
so i thought to ask it here.
ZurdoDev 23-Aug-16 9:15am    
ASP.Net is not the right technology for using timers unless you only want the timer to be on a single page and only when the user has that page open.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900