小编fma*_*ino的帖子

Thread.Sleep 或 Thread.Timer 挂系统?

我已经环顾四周一个多星期了,但找不到其他人遇到与我在这里看到的问题类似的问题。

我正在使用在 Windows XP 上运行并在 Visual Studio 2003 中开发的旧应用程序。大约 3 周前突然之间,应用程序变得没有响应,操作员必须执行 Windows 三指敬礼 (CTRL-ALT- DEL)调出任务管理器,终止应用程序进程(显示为无响应)并重新启动应用程序。

我设法让它在调试器中发生一次,当我暂停应用程序时,它正在等待系统从尝试设置 System.Windows.Forms.Timer.Interval 属性返回。

这是对象以及它似乎挂起的位置,这不是它在源代码中的编写方式

internal static System.Windows.Forms.Timer timerMtimeOut;

// This is in an initialization method.
timerMtimeOut = new System.Windows.Forms.Timer();   
timerMtimeOut.Tick += new System.EventHandler(timerMtimeOut_Tick);

// this is how it's value is set.
timerMtimeOut.Interval = 1 * msec;  // <-- This is where it was in the debugger
timerMtimeOut.Enabled = true;


private static void timerMtimeOut_Tick(object sender, System.EventArgs e)
{           
    mTimeOut +=timerMtimeOut.Interval/msec;
}
Run Code Online (Sandbox Code Playgroud)

应用程序基本上变得无响应,必须使用任务管理器关闭并重新启动。

多年来它一直运行良好,然后大约 2-3 周前才开始发生这种情况。

有没有其他人看到过这种行为?

c# multithreading visual-studio-2003 timer visual-studio

5
推荐指数
1
解决办法
893
查看次数