如何在网站不活动或没有人打开网站或绑定定时器控制的页面时使定时器控制工作 [英] How to make timer control work when website is not live or when no one has opened the website or that page on which timer control is bound

查看:64
本文介绍了如何在网站不活动或没有人打开网站或绑定定时器控制的页面时使定时器控制工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个页面,其中我附加了ajax的计时器控件。它的间隔为10秒。

当我在本地主机上运行它或在服务器上托管它时,计时器工作正常。

问题是当网站无法运行时(没有人登录时)到那个)

计时器控件没有执行计划任务。

所以任何人都可以帮我解决这个问题。

我是什么想要的是即使没有人打开那个页面或网站,我的计时器控制也应该工作

帮帮我



什么我试过了:



< asp:Timer ID =Timer1runat =serverInterval =600000ontick =Timer1_Tick> ;



protected void Timer1_Tick(对象发送者,EventArgs e)

{

//我想要的函数

}

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
}

推荐答案

asp.net是一个request \ response技术....你的代码是为响应请求而运行的。如果没有要求,你会怎么做?没什么,你的代码无法运行。这是asp.net中计划任务的问题,无法保证它们会运行。你可以使用quartz.net之类的东西来为你的现有代码做得更好,但仍然无法保证。



你需要做什么而是使用更合适的技术,如Windows服务或计划任务。
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.


您已经多次问过这个问题,答案仍然是一样的。不要使用ASP.Net。 ASP.Net不是按计划运行的。如您所知,ASP.Net中的代码仅在某人点击页面然后停止时运行。这就是它的工作原理。



你可以,虽然我建议反对它,但你可以创建一个批处理文件,其中包含你网页的网址并安排批处理文件每隔x分钟运行一次。这将每隔x分钟在您的页面上执行代码。



但是,如果您想要在计划运行时安排或定时或控制某些内容,请使用Windows控制台应用程序或一个Windows服务。
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.


这篇关于如何在网站不活动或没有人打开网站或绑定定时器控制的页面时使定时器控制工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆