您的位置:首页 > 编程语言 > ASP

ASP.NET定时发送邮件&windows server

2015-07-21 09:02 597 查看
System.Timers.Timer timer;

    void Application_Start(object sender, EventArgs e)

    {

      

        long ltime = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["lTick"]);

        timer = new System.Timers.Timer();

        timer.Interval = ltime;

        timer.Enabled = true;

        timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);

        timer.AutoReset = false;    

    }
    void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)

    {

        timer.Stop();

        timer.Enabled = false;

        SendMail();  具体的任务操作在这里写

        timer.Enabled = true;

        timer.Start();

    }

        

    void Application_End(object sender, EventArgs e)

    {

               timer.Dispose();

    }

 

http://www.cnblogs.com/JamesLi2015/archive/2008/10/23/1318196.html

创建windows server安装脚本

在项目中添加2个文件如下(必须是ANSI或者UTF-8无BOM格式):

1)安装脚本Install.bat

%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe WindowsServiceTest.exe Net Start ServiceTest sc config ServiceTest start= auto

2)卸载脚本Uninstall.bat

%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe /u WindowsServiceTest.exe

3)安装脚本说明

第二行为启动服务。

第三行为设置服务为自动运行。

这2行视服务形式自行选择。

4)脚本调试

如果需要查看脚本运行状况,在脚本最后一行加入pause
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: