系统进入待机状态并恢复时,多线程应用程序崩溃 [英] multithreaded application is crashing when system goes to standby and resumes

查看:72
本文介绍了系统进入待机状态并恢复时,多线程应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我不知道代码的哪一部分引发了异常.我的应用程序中具有USB自动检测功能.

引发的异常如下:

safe handle closed

   at Microsoft.Win32.UnsafeNativeMethods.GetOverlappedResult(SafeFileHandle hFile, NativeOverlapped* lpOverlapped, Int32& lpNumberOfBytesTransferred, Boolean bWait)
   at System.IO.Ports.SerialStream.EventLoopRunner.WaitForCommEvent()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()


请帮忙!

解决方案

最好检测那些事件,并在事件发生时停止/挂起线程.请查看下面有关检测这些事件的链接.

处理操作系统事件,例如睡眠,待机,休眠,电源状态已更改,电池电量低,临界挂起,交流电源,电池Windows XP和Vista中的电源,电池寿命等. [ ^ ]

使用系统事件来保护您的应用程序数据 [ 解决方案

It is best to detect those events and stop/suspend the thread(s) when they occur. Have a look at the links below about detecting these events.

Handling OS events like Sleep, Stand-by, Hibernate, Power Status Changed, Low Battery, Critial Suspend, AC Power, Battery Power, Battery Life etc... in Windows XP and Vista.[^]

Use System Events To Protect Your Application Data[^]

Good luck!


The 2nd link was in C#. Of course, the code in the article isn''t going to be an exact fit for your needs, but being a programmer, you shouldn''t have any issues extracting and adapting the code you need from it, right?


这篇关于系统进入待机状态并恢复时,多线程应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆