夜间运行时,Windows窗体应用程序随机冻结 [英] Windows Form application freeze randomly when run overnight

查看:735
本文介绍了夜间运行时,Windows窗体应用程序随机冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个窗口形式的应用程序,它具有运行,将调用主UI线程上更新UI多个线程。偶尔在开发计算机上,应用程序主UI线程将停止运行,并且应用程序不再响应。看来,如果我离开了应用程序运行在一夜之间发生。不过,我有谁​​跑这个窗口形式的应用程序,虽然远程桌面用户,如果应用程序是左无需用户交互运行一夜之间这个问题更经常发生了不少。



我找到一个文章似乎是描述这个问题,但我没有足够的Windows开发知识,找出原因该应用程序将冻结。



我得到的唯一信息是下面的堆栈跟踪,指示主UI线程在等待某种操作。



这个问题现在已困扰了我很长一段时间。我将不胜感激任何建议或意见。



谢谢!



 
主UI线程堆栈跟踪:

mscorlib.dll中System.Threading.WaitHandle.WaitOne(长超时,布尔exitContext)+值为0x2F字节
mscorlib.dll中System.Threading.WaitHandle.WaitOne(INT millisecondsTimeout! ,布尔exitContext)+ 0x25字节
System.Windows.Forms.dll中!System.Windows.Forms.Control.WaitForWaitHandle(System.Threading.WaitHandle的WaitHandle = {} System.Threading.ManualResetEvent)线路4268 C#
System.Windows.Forms.dll中!System.Windows.Forms.Control.MarshaledInvoke(System.Windows.Forms.Control的来电者,System.Delegate方法,对象[] ARGS,布尔同步)线7614 C#
系统。 Windows.Forms.dll!System.Windows.Forms.Control.Invoke(System.Delegate方法,对象[]参数)线7178 +为0x11字节C#
System.Windows.Forms.dll的!System.Windows.Forms的。 WindowsFormsSynchronizationContext.Send(System.Threading.SendOrPostCallback D,对象的状态),89号线C#
System.dll中!Microsoft.Win32.SystemEvents.SystemEventInvokeInfo.Invoke(布尔checkFinalization = TRUE,对象[] ARGS = {对象[2] })+ 0X62字节
System.dll中!Microsoft.Win32.SystemEvents.RaiseEvent(布尔checkFinalization = TRUE,对象键= {}对象,对象[] ARGS = {对象[2]})+ 0x10f字节
System.dll中!Microsoft.Win32.SystemEvents.OnUserPreferenceChanging(INT味精,System.IntPtr的wParam,lParam的System.IntPtr)+ 0x77字节
System.dll中!Microsoft.Win32.SystemEvents.WindowProc(System.IntPtr的HWND = 2032836,INT味精= 8218,System.IntPtr的wParam = 47,System.IntPtr的lParam = 100019840)+ 0x2ca字节
[原产于托管过渡]
[托管到本机过渡]
系统.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(INT dwComponentID,诠释原因= 4,INT pvLoopData = 0)线2106 +,位于0x8字节C#
System.Windows.Forms.dll中!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(INT原因= 4,System.Windows.Forms.ApplicationContext背景= {} System.Windows.Forms.Application.ModalApplicationContext)线路3377 + 0x1b字节C#
System.Windows.Forms.dll中!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(INT原因,System.Windows.Forms.ApplicationContext上下文)线3261 +字节是0xA C#
System.Windows.Forms.dll中!System.Windows.Forms.Application.RunDialog(System.Windows.Forms.Form中表格)线1488 C#
System.Windows.Forms.dll的!System.Windows.Forms.Form中。的ShowDialog(System.Windows.Forms.IWin32Window所有者)线6120 +,位于0x8字节C#
Schedule.exe!ME.APTS.ScheduleApp.ScheduleAppMainForm.ShowOpenScheduleForm.AnonymousMethod()行829 + 0xd中的字节C#
计划。 exe文件!ME.APTS.ScheduleApp.ScheduleAppMainForm.PromptUserToSaveSchedule(System.Action oAfterPromptUserToSaveCallBack = {方法=因为当前方法的代码进行了优化无法计算表达式。})线1858 + 0XB字节C#
Schedule.exe!ME .APTS.ScheduleApp.ScheduleAppMainForm.ShowOpenScheduleForm()行859 + 0XB字节C#
[原产于托管过渡]
[托管到本机过渡]
mscorlib.dll中!System.Delegate.DynamicInvokeImpl( [对象]参数)将0x55 +字节
System.Windows.Forms.dll中!System.Windows.Forms.Control.InvokeMarshaledCallbackDo(System.Windows.Forms.Control.ThreadMethodEntry TME)线7266 + 0XB字节C#
System.Windows.Forms.dll中!System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(obj对象)线7228 + 0x7的字节C#
mscorlib.dll中!System.Threading.ExecutionContext.runTryCode(对象USERDATA)+ 0x51字节
[原产于托管过渡]
[托管到本机过渡]
mscorlib.dll中!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext的ExecutionContext,System.Threading.ContextCallback回调,对象状态)+ 0x67字节
mscorlib.dll中!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext的ExecutionContext,System.Threading.ContextCallback回调,对象的状态)+字节×45
System.Windows。 Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallback(System.Windows.Forms.Control.ThreadMethodEntry TME)线7213 + 0xffffffc5字节C#
System.Windows.Forms.dll中!System.Windows.Forms.Control的.InvokeMarshaledCallbacks()线7297 + 0XB字节C#
System.Windows.Forms.dll中!System.Windows.Forms.Control.WndProc(参考System.Windows.Forms.Message米)线13848 C#
系统.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(参考System.Windows.Forms.Message米)线1491 C#
System.Windows.Forms.dll的!System.Windows.Forms.ContainerControl。的WndProc(参考System.Windows.Forms.Message M)1898年线C#
System.Windows.Forms.dll中!System.Windows.Forms.Form.WndProc(参考System.Windows.Forms.Message米)线7515 C#
System.Windows.Forms.dll中!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(参考System.Windows.Forms.Message米)线14051 C#
System.Windows.Forms.dll中!系统.Windows.Forms.Control.ControlNativeWindow.WndProc(参考System.Windows.Forms.Message米)线14106 C#
System.Windows.Forms.dll中!System.Windows.Forms.NativeWindow.Callback(System.IntPtr的HWND ,INT味精= 49512,System.IntPtr WPARAM,LPARAM System.IntPtr)线647 +字节是0xA C#
System.Windows.Forms.dll中!System.Windows.Forms.NativeWindow.DefWndProc(参考System.Windows.Forms的.Message M = {} System.Windows.Forms.Message)线814​​ + 0x1d字节C#
System.Windows.Forms.dll中!System.Windows.Forms.NativeWindow.WndProc(REF System.Windows.Forms.Message M)1409行C#
Infragistics2.Win.UltraWinToolbars.v8.1.dll!Infragistics.Win.UltraWinToolbars.UltraToolbarsManager.FormSubClasser.WndProcImpl(参考System.Windows.Forms.Message米)+ 0x17f5字节
Infragistics2.Win.UltraWinToolbars.v8.1.dll!Infragistics.Win.UltraWinToolbars.UltraToolbarsManager.FormSubClasser.WndProc(参考System.Windows.Forms.Message米)+ 0x5的字节
System.Windows.Forms.dll中!系统.Windows.Forms.NativeWindow.Callback(System.IntPtr的HWND,INT味精= 49512,System.IntPtr WPARAM,LPARAM System.IntPtr)线647 +字节是0xA C#
[原产于托管过渡]
[托管到本机过渡]
System.Windows.Forms.dll中!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(INT dwComponentID,诠释原因= -1,INT pvLoopData = 0)线2106 +,位于0x8字节C#
System.Windows.Forms.dll中!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(INT原因= -1,System.Windows.Forms.ApplicationContext背景= {系统.Windows.Forms.ApplicationContext})线3377 + 0x1b字节C#
System.Windows.Forms.dll中!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(INT原因,System.Windows.Forms.ApplicationContext上下文)线3261 +为0xA字节C#
System.Windows.Forms.dll中!System.Windows.Forms.Application.Run()线1457 C#
Schedule.exe!ME.APTS.ScheduleApp.ScheduleApp.LoadData( )行318 + 0x5的字节C#
Schedule.exe!ME.APTS.ScheduleApp.ScheduleApp.Run()行170 + 0x9字节C#
Schedule.exe!ME.APTS.ScheduleApp.ScheduleApp.Main( )行126 + 0XB字节C#


解决方案

我经历了大约一年前,这个相同的问题(一段时间后,应用程序挂起无需用户交互,以 OnUserPreferenceChanging()



最有可能的调用堆栈)。原因是你使用 InvokeRequired / 的invoke()上的控件,而不是主要形式。这有时会产生,如果控件的句柄尚未产生错误的结果。



解决的办法是随时拨打 InvokeRequired / 的invoke()主窗口(您可以转换为一个 ISynchronizeInvoke 如果你不想。引进的依赖关系到你的窗体类)



您可以找到原因和解决方案的这里


I have a window form application, and it has multiple threads running that would invoke on the Main UI thread to update the UI. Occasionally on development machine, the application main UI thread will stop running, and the application no longer responses. It seems to happen if I left the application running overnight. However, I have users who run this window form application though remote desktop, and this problem happen a lot more often if the application is left running overnight with no user interaction.

I have find an article seems to be describing this problem, but I don't have enough Windows development knowledge to figure out why the application would freeze.

The only information I got is the following stack trace, indicating the main UI thread is waiting for some kind of operation.

This problem has been bothering me for quite some time now. I would appreciate any suggestions or comments.

Thanks!

Main UI thread stack trace:

mscorlib.dll!System.Threading.WaitHandle.WaitOne(long timeout, bool exitContext) + 0x2f bytes
mscorlib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout, bool exitContext) + 0x25 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.WaitForWaitHandle(System.Threading.WaitHandle waitHandle = {System.Threading.ManualResetEvent}) Line 4268 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.MarshaledInvoke(System.Windows.Forms.Control caller, System.Delegate method, object[] args, bool synchronous) Line 7614 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.Invoke(System.Delegate method, object[] args) Line 7178 + 0x11 bytes C#
System.Windows.Forms.dll!System.Windows.Forms.WindowsFormsSynchronizationContext.Send(System.Threading.SendOrPostCallback d, object state) Line 89 C#
System.dll!Microsoft.Win32.SystemEvents.SystemEventInvokeInfo.Invoke(bool checkFinalization = true, object[] args = {object[2]}) + 0x62 bytes
System.dll!Microsoft.Win32.SystemEvents.RaiseEvent(bool checkFinalization = true, object key = {object}, object[] args = {object[2]}) + 0x10f bytes
System.dll!Microsoft.Win32.SystemEvents.OnUserPreferenceChanging(int msg, System.IntPtr wParam, System.IntPtr lParam) + 0x77 bytes
System.dll!Microsoft.Win32.SystemEvents.WindowProc(System.IntPtr hWnd = 2032836, int msg = 8218, System.IntPtr wParam = 47, System.IntPtr lParam = 100019840) + 0x2ca bytes
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = 4, int pvLoopData = 0) Line 2106 + 0x8 bytes C#
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = 4, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.Application.ModalApplicationContext}) Line 3377 + 0x1b bytes C#
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Line 3261 + 0xa bytes C#
System.Windows.Forms.dll!System.Windows.Forms.Application.RunDialog(System.Windows.Forms.Form form) Line 1488 C#
System.Windows.Forms.dll!System.Windows.Forms.Form.ShowDialog(System.Windows.Forms.IWin32Window owner) Line 6120 + 0x8 bytes C#
Schedule.exe!ME.APTS.ScheduleApp.ScheduleAppMainForm.ShowOpenScheduleForm.AnonymousMethod() Line 829 + 0xd bytes C#
Schedule.exe!ME.APTS.ScheduleApp.ScheduleAppMainForm.PromptUserToSaveSchedule(System.Action oAfterPromptUserToSaveCallBack = {Method = Cannot evaluate expression because the code of the current method is optimized.}) Line 1858 + 0xb bytes C#
Schedule.exe!ME.APTS.ScheduleApp.ScheduleAppMainForm.ShowOpenScheduleForm() Line 859 + 0xb bytes C#
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.Delegate.DynamicInvokeImpl(object[] args) + 0x55 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackDo(System.Windows.Forms.Control.ThreadMethodEntry tme) Line 7266 + 0xb bytes C#
System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(object obj) Line 7228 + 0x7 bytes C#
mscorlib.dll!System.Threading.ExecutionContext.runTryCode(object userData) + 0x51 bytes
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x67 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x45 bytes
System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallback(System.Windows.Forms.Control.ThreadMethodEntry tme) Line 7213 + 0xffffffc5 bytes C#
System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbacks() Line 7297 + 0xb bytes C#
System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) Line 13848 C#
System.Windows.Forms.dll!System.Windows.Forms.ScrollableControl.WndProc(ref System.Windows.Forms.Message m) Line 1491 C#
System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.WndProc(ref System.Windows.Forms.Message m) Line 1898 C#
System.Windows.Forms.dll!System.Windows.Forms.Form.WndProc(ref System.Windows.Forms.Message m) Line 7515 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Line 14051 C#
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Line 14106 C#
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 49512, System.IntPtr wparam, System.IntPtr lparam) Line 647 + 0xa bytes C#
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) Line 814 + 0x1d bytes C#
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.WndProc(ref System.Windows.Forms.Message m) Line 1409 C#
Infragistics2.Win.UltraWinToolbars.v8.1.dll!Infragistics.Win.UltraWinToolbars.UltraToolbarsManager.FormSubClasser.WndProcImpl(ref System.Windows.Forms.Message m) + 0x17f5 bytes
Infragistics2.Win.UltraWinToolbars.v8.1.dll!Infragistics.Win.UltraWinToolbars.UltraToolbarsManager.FormSubClasser.WndProc(ref System.Windows.Forms.Message m) + 0x5 bytes
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 49512, System.IntPtr wparam, System.IntPtr lparam) Line 647 + 0xa bytes C#
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = -1, int pvLoopData = 0) Line 2106 + 0x8 bytes C#
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) Line 3377 + 0x1b bytes C#
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Line 3261 + 0xa bytes C#
System.Windows.Forms.dll!System.Windows.Forms.Application.Run() Line 1457 C#
Schedule.exe!ME.APTS.ScheduleApp.ScheduleApp.LoadData() Line 318 + 0x5 bytes C#
Schedule.exe!ME.APTS.ScheduleApp.ScheduleApp.Run() Line 170 + 0x9 bytes C#
Schedule.exe!ME.APTS.ScheduleApp.ScheduleApp.Main() Line 126 + 0xb bytes C#

解决方案

I experienced this exact same issue about a year ago (application hang after some time without user interaction, with OnUserPreferenceChanging() in the call stack).

The most likely cause is that you're using InvokeRequired/Invoke() on a control and not on the main form. This sometimes produces the wrong result if the control's handle hasn't been created yet.

The solution is to always call InvokeRequired/Invoke() on the Main Window (which you can cast as an ISynchronizeInvoke if you don't want to introduce a dependency to your form class).

You can find an excellent, very detailed description of the cause and solution here.

这篇关于夜间运行时,Windows窗体应用程序随机冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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