工作,我在我的程序中的线程它运行例如定时器功能为什么C#线程停止自动
Thread PopMonitoringThread = new Thread(new ThreadStart(PopMonitoring));
PopMonitoringThread.Start();
public static void PopMonitoring()
{
TimerCallback callback = new TimerCallback(Tick);
Timer stateTimer = new Timer(callback, null, 0, 1000);
}
//Timer method
static public void Tick(Object stateInfo)
{
try
{
if (Properties.Settings.Default.BatchingMode > 0)
{
if (batchTime.Subtract(DateTime.Now) < TimeSpan.Zero)
{
batchTime = DateTime.Now.AddMinutes(Properties.Settings.Default.BatchingMode);
Console.WriteLine("-----------------------------------------------------");
Process();
Console.WriteLine("Batch Process Run");
Console.WriteLine("-----------------------------------------------------");
}
Console.WriteLine("{0}", DateTime.Now.ToString("h:mm:ss"));
}
Console.WriteLine("Pop3 Monitoring start after: {0}", batchTime.Subtract(DateTime.Now));
}
catch (Exception e)
{
throw e;
}
}
当我注释掉我process()方法,它工作正常每一秒钟我的定时器互为作用的作品 但当我取消注释从我的Tick方法计时器的Process方法停止工作,即Tick方法停止工作。 过程方法代码正在运行完美,意味着没有编译和运行时错误。
你在'Process'中做了什么? – RoadBump 2013-02-22 05:08:39
我的流程方法从pop3 gmail中读取邮件,然后筛选并发送httpwebrequest到我的mvc3应用程序 – Raj 2013-02-22 05:12:39
流程可能比您设置的时间间隔长。因为您正在接受外部服务,请考虑增加轮询频率。 – 2013-02-22 05:15:20