• 大小: 22KB
    文件类型: .7z
    金币: 2
    下载: 1 次
    发布日期: 2021-06-12
  • 语言: C#
  • 标签: C#  定时任务  多任务  

资源简介

C#实现的自定义定时任务 可定时运行 多任务运行

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.xml;
using System.Data.SqlClient;
using System.IO;

namespace CalcAnnualleave
{
    public class AnnualLeave : TimingTaskbase.TimingTaskbase 
    {
        private static string connString;        

        static AnnualLeave()
        {
            xmlDocument docConfig = new xmlDocument();
            docConfig.Load(System.Environment.CurrentDirectory + “/TimingTaskConfig.xml“);
            xmlNode xnl = docConfig.SelectSingleNode(@“//Task[@ID=‘1‘]“);

            connString = xnl.Attributes[“connString“].Value;            
        }       

        public override void Run()
        {
            CalcAnnual();
        }

        private static void CalcAnnual()
        {
            DateTime dtNow = DateTime.Now;
            string strSql = @“update dbo.VocationAndJiaBanReport set ThisYearHasNian = ThisYearHasNian + 1 “;
            string strsql2 = “select LastSuccessTime from dbo.TimingTaskInfo where TaskName = ‘Annual Leave‘“;


            SqlConnection conn = new SqlConnection(connString);
            try
            {
                conn.Open();
                SqlCommand cmmd = new SqlCommand(strSql conn);
                cmmd.ExecuteNonQuery();

                cmmd = new SqlCommand(“update dbo.TimingTaskInfo set LastSuccessTime = ‘“ + dtNow + “‘ where TaskName = ‘Annual Leave‘“ conn);
                cmmd.ExecuteNonQuery();            
            }
            catch
            {
                conn.Close();
                conn.Dispose();
            }
            finally
            {                    
                conn.Close();
                conn.Dispose();
            }
        }
    }
}

评论

共有 条评论