2020年10月13日星期二

Global定时器任务使用。.NET定时执行方法

using System;using System.Collections.Generic;using System.Linq;using System.Threading;using System.Web;using System.Web.Optimization;using System.Web.Routing;using System.Web.Security;using System.Web.SessionState;using BLL;using DAL;using DingTalk.Api.Response;using Model;using Newtonsoft.Json.Linq;using DingTalk.Api;using DingTalk.Api.Request;//using MyWeb.Common;using static DingTalk.Api.Response.OapiDepartmentListResponse;using System.Text;using System.Data;using System.Data.SqlClient;using static DingTalk.Api.Response.OapiAttendanceListscheduleResponse;using Newtonsoft.Json;using static DingTalk.Api.Response.OapiProcessinstanceGetResponse;using System.Configuration;using System.Net;using System.IO;namespace MyProject{ public class Global : HttpApplication {    void Application_Start(object sender, EventArgs e)  {   // 在应用程序启动时运行的代码。更新完,打   Thread t1 = new Thread(new ThreadStart(time001));   t1.Start();   Thread t2 = new Thread(new ThreadStart(time002));   t2.Start();   Thread t3 = new Thread(new ThreadStart(time003));   t3.Start();     }  #region 定时器---获取钉钉全部通讯录人员  private void time001()  {   System.Timers.Timer MyTimerGetdingdingUser = new System.Timers.Timer();   //MyTimerGetdingdingUser.Elapsed += GetMyUser;   MyTimerGetdingdingUser.Interval = 1000 * 60 * 60;//每天触发一次1000是一秒   //MyTimerGetdingdingUser.Interval = 1000 * 120;//每天触发一次1000是一秒   MyTimerGetdingdingUser.Enabled = true;   MyTimerGetdingdingUser.AutoReset = true;   MyTimerGetdingdingUser.Start();   MyTimerGetdingdingUser.Elapsed += new System.Timers.ElapsedEventHandler(GetMyUser);  }