asp.net中的定时器控件 [英] Timer control in asp.net

查看:60
本文介绍了asp.net中的定时器控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个asp.net应用程序,我添加了一个间隔为1000毫秒的计时器控件。我面临三种类型的问题:



1)页面在浏览器中查看时,每秒都会加载自己,并且会有计时器间隔。

我不希望这样,因为应用程序会非常繁重,如果最终应用程序不断重新加载它,那将完全失败。



2)计时器的目的是每秒检查一次时间和日期,当正确的时间接近时,它应该发送一封电子邮件。此功能无效。我正在使用下面的代码。

Hi,
I have an asp.net application where I have added a timer control with interval of 1000ms. I am facing three types of problems:

1) The page, when viewed in browser, is loading itself every second, with the interval of timer.
I do not want this as the application is going to be quite heavy and if final application keeps re-loading it like this, it will be a total failure.

2) The purpose of the timer is to check the time and date every second, when the right time approaches, it should send an email. This function is not working. I am using below code.

If DateTime.Now = DateTime.Parse("01.13.2014 20:34") Then
            Call SendEmail()
            Timer1.Enabled = False
        End If





3我想使用DateTimePicker设置这个时间,就像我们用于Winforms的控件一样。有可能吗?当在服务器上托管时,应该花时间在本地服务器上,它从我的系统中获取。



谢谢



3) I want to set this time using DateTimePicker like control, that we use for Winforms. Is anything like that possible? When hosted on server, where shall the time be taken, as on local server, it is taking from my system.

Thanks

推荐答案

对于发送邮件,您可以创建控制台应用程序并将其添加到 Windows任务计划程序

您可以选择日期和时间何时开始并设置重复频率。



当达到时间间隔时,它会自动触发重复一遍。
For sending mails, you can create Console Application and add that to the Windows Task Scheduler.
You can select the Date and Time when to start and also set the repetition frequency.

It would automatically trigger, when the time interval is reached and repeat itself.


我刚刚发现我们只需要添加 Global.asax 文件(右键单击服务器资源管理器中的项目和添加新项目>>添加全局应用程序)



只需将您的电子邮件代码放入文件中即可。托管时,即使浏览器已关闭,它也会通过IIS运行。
I have just discovered that we only need to add Global.asax file (right click project in server explorer and Add New Item>> Add Global Application)

Just put your email code in the file. When hosted, it runs through IIS, even though browser is closed.


这篇关于asp.net中的定时器控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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