zoukankan      html  css  js  c++  java
  • 简单的定时任务

    View Code
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using TxtControl;
    using DataControl;
    
    namespace WinFormSendSMS
    {
        public partial class SendSMS : Form
        {
            private System.Timers.Timer theTimer = new System.Timers.Timer();//定时器
            private double timespan;//服务执行的时间间隔
    
            public SendSMS()
            {
                InitializeComponent();
            }
    
            private void btnStart_Click(object sender, EventArgs e)
            {
    
    
                try
                {
    
                    TxtCommon tcomm = new TxtCommon();
                    DataUtility dUtility = new DataUtility();
                    this.theTimer.Elapsed += new System.Timers.ElapsedEventHandler(this.theTimer_Elapsed);
                    timespan = Convert.ToDouble(System.Configuration.ConfigurationManager.AppSettings["jianGeMinute"]);
                    theTimer.Interval = timespan * 60 * 1000; //转换为毫秒
                    theTimer.Enabled = true;
                    theTimer.Start();
    
                    this.btnStart.Enabled = false;
                    this.btnStart.Text = "已启动...";
                    btnStop.Enabled = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("error:" + ex.Message);
                }
            }
    
    
    
            /// <summary>
            /// 定时任务处理过程
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void theTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
    
                try
                {
                    LogMgr.WriteLine("--====定时开始执行程序!===-----");
                    TxtCommon tcomm = new TxtCommon();
                    DataUtility dUtility = new DataUtility();
                    //接收A8表里的数据,放到list
                    List<SMSEntity> orginalList = A8DataControl.SMSList();
                    LogMgr.WriteLine("获得" + orginalList.Count + "条数据");
                    if (orginalList.Count > 0)
                    {
    
                        ProcessSMS process = new ProcessSMS();
                        process.ProcessInfo(orginalList);
                    }
                    LogMgr.WriteLine("--====定时开始执行程序!end===-----");
                }
                catch (Exception ex)
                {
                    LogMgr.WriteLine("定时开始执行程序出现异常:" + ex.Message);
    
                }
            }
    
            /// <summary>
            /// 关闭定时任务
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void btnStop_Click(object sender, EventArgs e)
            {
    
                this.theTimer.Enabled = false;
                this.btnStart.Enabled = true;
                this.btnStart.Text = "开启";
                btnStop.Enabled = false;
    
    
            }
    
    
    
        }
    }

    作者:沐雪
    文章均系作者原创或翻译,如有错误不妥之处,欢迎各位批评指正。本文版权归作者和博客园共有,如需转载恳请注明。
    如果您觉得阅读这篇博客让你有所收获,请点击右下方【推荐】
    找一找教程网-随时随地学软件编程 http://www.zyiz.net/

  • 相关阅读:
    vue中 $event 的用法--获取当前父元素,子元素,兄弟元素
    vue的通信方式(二)---祖父孙三个级别的之间的隔代通信
    js获取当前页面url信息
    解决Vue刷新一瞬间出现样式未加载完或者出现Vue代码问题
    Java POI读取excel中数值精度损失
    Java读取Excel数值内容带.0或变科学计数法的解决办法
    Java专业术语
    jdbc连接数据库
    阿里云linux配置ftp服务
    mybatis批量更新表setting parameters 错误
  • 原文地址:https://www.cnblogs.com/puzi0315/p/2746467.html
Copyright © 2011-2022 走看看