简体   繁体   中英

Application.Run(form) is hanging

I have a very strange situation. We have a relatively large app (~500K lines of code), developed by upwards of 10 different developers over the last 6 years. It has been working fine until our most recent release. With the latest build, we have multiple customers complaining that it is sporadically hanging and we are having a heck of a time figuring out how/why! Here are some of the things making it challenging to debug:

  • Until this morning, we have been totally unable to reproduce this problem in house.
  • We have never seen this happen when the debugger is attached! This obviously makes it challenging to solve.
  • This does not tend to happen when people are using the app, but rather after they've stopped using it for some time.
  • Could this (maybe) be related to the screen saver coming on?
  • It seems to happen somewhat consistently when changing screen resolutions

This morning we finally figured out how to reproduce at least one scenario in house by: - Running that app outside of the debugger - Changing the screen resolution. This hangs the app. - Then we can attach with the debugger.

The problem though (now that we can, at least in one case, reproduce it) is that ! In other words, there is only one thread running at the time it hangs, and the line it breaks on is the Application.Run(form); from program.cs.

One final point is that the application is not completely hung . Specifically: - It still does screen painting (refreshes parts of the screen covered by other apps for example) - I can't click on the UI elements that are shown, but it also doesn't "beep" at me like I would expect if it were completely unresponsive - When I "pause" the application after attaching the debugger, I can minimize/maximize it while paused. Otherwise, it won't respond to minimize/maximize commands. - Other than not beeping at me, it behaves as though there is a modal window off-screen that I just can't see. Additional (as mentioned before), when I pause the app, it pauses on the Application.Run line, and there are no other threads/code running in the threads list (as I would expect to see if there were a modal dialog box blocking the main window.

The behavior is most strange IMHO - especially since it has only recently started happening. My next steps are going to have to be to start "subtracting" sections of the code until I find the culprit, but I figured I'd throw the problem up here first and see if anyone else has ever experienced anything like this before.

Thanks in advance for any guidance - I look forward to hearing any suggestions.

ej

Edit: Another way of stating the behavior. After it has "hung" it behaves as though it has no problem, except that it receives no messages from my mouse and keyboard. In other words, it still repaints itself, and can be paused by the VS2010 debugger, but does not respond in any way shape or form to mouse/keyboard events. Here again though, it doesn't start beeping at me as it does with other apps that are truly dead. Like, it does not show as being unresponsive in the task manager. It's just in a sort of weird "I'm not listening for I/O anymore, sorry!" state... Strange!

Edit:

In my last edit, I mentioned that it was not accepting IO anymore. This got me thinking so, I added a TcpListener to see if that would still respond after it "hung" - and it does. Additionally, in thinking about the fact that it still updates the screen, I put a breakpoint in the paint event and got some (more) odd behavior. It hits the breakpoint in the paint event, but is NOT at the top of the call stack at that point. The top of the callstack shows "In sleep, wait or join". Then the line in paint is next, then external code, then main. So the line highlighted on the screen is Green - not Yellow. Additionally, if I F10 (to step over), it does, moving down exactly 1 line, but still, the pain method is not at the top of the call stack. At this point, there are no other threads running, no other code executing, nothing else happening?!?! What is going on here?

One final point - I set a breakpoint in the TcpListener's Accept Socket event, and when I connect to the TCP/IP port, it breaks on that code, and that code IS at the top of the call stack.

Sorry - But I'm still quite confused.

您可能在非UI线程上创建控件(或其句柄)时遇到问题请检查此问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM