当前位置:   article > 正文

C#窗体定时执行任务_c#定时任务每15分钟执行一次

c#定时任务每15分钟执行一次
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Timers;


namespace test
{
    public partial class Form8 : Form
    {
        public Form8()
        {
            InitializeComponent();


            System.Timers.Timer aTimer = new System.Timers.Timer();
            aTimer.Elapsed += new ElapsedEventHandler(TimeEvent);
            // 设置触发事件的时间间隔 此处设置为1秒(1000毫秒) 
            aTimer.Interval = 1000;
            aTimer.Enabled = true;
        }

        private void Form8_Load(object sender, EventArgs e)
        {
        }

        private  void TimeEvent(object source, ElapsedEventArgs e)
        {
            // 得到 hour minute second  如果等于某个值就开始执行某个程序。 
            int intHour = DateTime.Now.Hour;
            int intMinute = DateTime.Now.Minute;
            int intSecond = DateTime.Now.Second;
            // 定制时间; 比如 在10:30 :00 的时候执行某个函数 
            int iHour = 10;
            int iMinute = 30;
            int iSecond = 00;
            // 设置 每分钟的开始执行一次 
            if (intSecond == iSecond)
            {
                MessageBox.show("每分钟的开始执行一次!");
                OpenIEWindow("http://www.baidu.com");
            }
            // 设置 每个小时的30分钟开始执行 
            if (intMinute == iMinute && intSecond == iSecond)
            {
                MessageBox.show("每个小时的30分钟开始执行一次!");
            }


            // 设置 每天的10:30:00开始执行程序 
            if (intHour == iHour && intMinute == iMinute && intSecond == iSecond)
            {
               MessageBox.show("在每天10点30分开始执行!");
            }
        }
        //调用浏览器打开某个网页
        private  void OpenIEWindow(string url)
        {
            System.Diagnostics.Process.Start("C:\\Program Files\\Internet Explorer\\iexplore.exe", url);
        }

        private void Form8_MouseLeave(object sender, EventArgs e)
        {
            this.Opacity = 0.1;
        }

        private void Form8_MouseHover(object sender, EventArgs e)
        {
            this.Opacity = 1;
        }
    }

}

网上搜到是控制台程序,稍微修改了一下就成窗体程序了

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号