/// <summary>
/// 方法入口
/// </summary>
public void StartPollingThread()
{
System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
t.Interval = 1;
t.Tick += new System.EventHandler(this.timerStart_Tick);
t.Start();
}
private void timerStart_Tick(object sender, EventArgs e)
{
System.Windows.Forms.Timer timer = (sender as System.Windows.Forms.Timer);
timer.Stop();
timer.Dispose();
new Thread(delegate () { PollingThread(timer); }).Start();
}
private void PollingThread(System.Windows.Forms.Timer timer)
{
try
{
//我设置的每晚1点执行
timer.Interval = Convert.ToInt32(Math.Ceiling((DateTime.Now.AddDays(1).AddHours(1).Date - DateTime.Now).TotalMilliseconds));
//主要业务
Init();
}
catch (Exception ex) { richTextBox1.AppendText(ex.Message + DateTime.Now + "\r\n"); }
this.Invoke(new Action(() => { timer.Start(); }));
}