C# System.Threading.Timer无故停止
我正在windows服务(控制台应用程序)项目中使用C# System.Threading.Timer无故停止,c#,multithreading,events,timer,handler,C#,Multithreading,Events,Timer,Handler,我正在windows服务(控制台应用程序)项目中使用系统.Threading.Timer 长时间后,系统.Threading.Timer会无故停止 我怎样才能检查这个并使它重新工作 public static System.Threading.Timer ProcessorTimer = null; private static readonly object _ProcessorTimerLockObject = new object(); private static TimerCallba
系统.Threading.Timer
长时间后,系统.Threading.Timer
会无故停止
我怎样才能检查这个并使它重新工作
public static System.Threading.Timer ProcessorTimer = null;
private static readonly object _ProcessorTimerLockObject = new object();
private static TimerCallback ProcessorTimerCallback;
public DeviceConnectControlProcessor()//class constructor
{
ProcessorTimerCallback = ProcessorTimer_Tick;
ProcessorTimer = new System.Threading.Timer(ProcessorTimerCallback, null, 0,
(1 * 60000));
}
private void ProcessorTimer_Tick(object sender)
{
if (Monitor.TryEnter(_ProcessorTimerLockObject))
{
try
{
//kod
}
catch (Exception)
{
}
finally
{
Monitor.Exit(_ProcessorTimerLockObject);
GC.Collect();
}
}
}
你说的“停止”是什么意思?
ProcessorTimer\u Tick
是否不再输入(您是如何验证的)?或者“//kod”中的代码正在等待某些东西,以便无法再输入锁?另外,您在(实例)构造函数中初始化静态字段ProcessorTimer
,这有点奇怪。为什么不在类型初始值设定项(也称为静态构造函数)中执行此操作?GC.Collect()
行的意图是什么?您好!1) //kd ping域中的一个设备,然后将其写入日志2)大约5~10小时后,它停止并不再记录3)以清理我在GC.Collect()中创建的实例(//kod=Code)很抱歉没有用英语编写