|
-
Dec 5th, 2005, 11:00 AM
#1
Program freezing [Resolved--Oddly]
I'm not sure that this is the right audience, and I haven't gotten to spend ANY time diagnosing this yet (I just figured it out this morning), but I thought I might put it up on the board in case anybody had some suggestions.
I have a program that takes several days to run. Basically, I start it running on a system, then go away and do other things, checking on it occasionally. This seems to be running ok on two of the systems. There is a bug in it somewhere, since one of the systems eventually gave me a Object not set to an instance values, but that only arose after three days of constant running. A problem as intermittent as that will be darn hard to track down, but at least I know it is there.
On one of the systems, the screen goes to screen saver mode, then it shuts off. The OS is XP Pro. To recover from this sleep mode, I press any key and enter a password. However, when I recover from sleep mode, the program is locked up. According to CPU usage, it is still running, and appears to be doing something, but the form never refreshes itself. The program is running in a long loop, and every time through the loop it should hit a me.Refresh call. However, clicking on the program just tells me that the program is not responding. At that point, I use the task manager to end the program.
When I reload the program (it saves itself every so often), I find that it must have stopped running at some point fairly early on. I assume (I haven't played with it enough to do more than assume) that when the system goes into sleep mode, the program suspends. Naturally, this is not a good thing when the program takes about four days to complete.
My next step is to turn off sleep mode. However, I'm not sure why a running program would fail to respond once the system has been brought out of sleep mode. Other programs don't behave that way. Furthermore, this one may not be hung exactly, since CPU usage remains fairly high. What may be happening is that the loop is running, but the main window will not re-draw itself.
Any suggestions as to what could be causing it to perform like this?
Last edited by Shaggy Hiker; Dec 10th, 2005 at 12:42 PM.
My usual boring signature: Nothing
 
-
Dec 5th, 2005, 11:20 AM
#2
Member
Re: Program freezing
Try putting in Application.DoEvents in your loop.
-
Dec 5th, 2005, 11:25 AM
#3
Addicted Member
Re: Program freezing
I know that with services, you can handle the different power events and perform some cleanup code based on those events. I don't know for certain, but is there anything that a desktop application has to have in it to correctly handle power events?
Even though I could be way off, my thoery is this: I'm thinking that the loop is executing, but when the computer goes into sleep mode, the loop just kind of...suspends itself. When the computer comes back from sleep mode, the loop doesn't know to restart, so it just stays suspended until you end it.
Kyjan
-
Dec 5th, 2005, 11:34 AM
#4
Re: Program freezing
 Originally Posted by dreamr
Try putting in Application.DoEvents in your loop.
It's already there.
My usual boring signature: Nothing
 
-
Dec 5th, 2005, 11:36 AM
#5
Re: Program freezing
 Originally Posted by Kyjan
I know that with services, you can handle the different power events and perform some cleanup code based on those events. I don't know for certain, but is there anything that a desktop application has to have in it to correctly handle power events?
Even though I could be way off, my thoery is this: I'm thinking that the loop is executing, but when the computer goes into sleep mode, the loop just kind of...suspends itself. When the computer comes back from sleep mode, the loop doesn't know to restart, so it just stays suspended until you end it.
Kyjan
That would fit the facts as I currently understand them. A thoroughly undesireable result, too. I'll look into app events, but the suspension itself is unfortunate.
My usual boring signature: Nothing
 
-
Dec 5th, 2005, 11:58 AM
#6
Re: Program freezing
I have seen this situation before too. It happens mostly in single threaded applications. Layout presentation of windows takes place in your main application thread, which is suspended when the system enters sleep/suspend mode (as you'd expect). When you recover, the thread is resumed, but since you are in an intensive loop the window never gets the chance to refresh.
To get around this, you could shift your loop into a secondary thread. That should allow the window to update when the system is resumed, and allow your loop to continue simultaneously.
-
Dec 5th, 2005, 12:22 PM
#7
Re: Program freezing
 Originally Posted by penagate
I have seen this situation before too. It happens mostly in single threaded applications. Layout presentation of windows takes place in your main application thread, which is suspended when the system enters sleep/suspend mode (as you'd expect). When you recover, the thread is resumed, but since you are in an intensive loop the window never gets the chance to refresh.
To get around this, you could shift your loop into a secondary thread. That should allow the window to update when the system is resumed, and allow your loop to continue simultaneously.
I was thinking about doing that just yesterday, but didn't feel that I had adequate reason to do so. Now it appears that I do. I'll give it a go.
My usual boring signature: Nothing
 
-
Dec 5th, 2005, 03:30 PM
#8
Re: Program freezing
After all of about 30 seconds of testing (in other words: far from thorough), it appears that if the OS goes to the screen saver, that doesn't influence behavior of the program. I have to re-log in to get back to the program, but it is running fine. There is a setting for turning off the screen, and I have turned that off. I'll see how that does later on. I assumed this was a sleep mode, but it doesn't really look like one. I may have the diagnosis wrong.
My usual boring signature: Nothing
 
-
Dec 5th, 2005, 04:44 PM
#9
Addicted Member
Re: Program freezing
From what you're saying, you're talking about what's in the display properties. You might also want to check your Power options (accessible from the Control Panel) and make sure that your hard drive isn't powering down after a period of time. Also, make sure that any other standby features are disabled.
Kyjan
-
Dec 5th, 2005, 06:21 PM
#10
Re: Program freezing
Looks like nothing is powering down now. I'll check this evening to see whether it made a difference.
My usual boring signature: Nothing
 
-
Dec 10th, 2005, 12:42 PM
#11
Re: Program freezing
It turns out I had this diagnosis completely wrong.
I did switch the loop into a separate thread, which I like, though it had only a minor improvement in efficiency. However, after running that for some time, I found that it would occasionally still freeze, but only the second thread!! The main thread wouldn't freeze at all. Cool.
This morning, I found that it had frozen (by pure chance) immediately after saving itself. This meant that the saved state was one that would freeze the computer, so I could load the saved file into the debug version, and see what was happening. This is pure chance, since the program had run fine on three computers for days. For some reason, this one version of data had brought the computer to a hanging state every so often.
The problem was that a certain set of circumstances could throw the program into a perpetual loop. I thought I had dealt with that unusual circumstance, but it turned out that there was a case I had overlooked. Why it seemed to happen with one data set and not any others is a total mystery. Even with this data set, the program (which is an evolutionary GA), ran for half a million generations before hanging. VERY hard to find.
The whole bit with the monitor suspending was a red herring dragged across the track of the bug. The bug only manifested once every few hundred generations, and the computer always managed to turn off the monitor before that time had elapsed. Until the program happened to save state immediately prior to the situation, I was convinced this was an OS issue. It was only pure chance that I caught it.
Of course, once I found that the second thread was hanging while the main thread worked, I could have figured out that it was a perpetual loop, but since it was sooooo intermittent, it would have been hell figuring out where the loop was occuring, since the whole program is a loop.
My usual boring signature: Nothing
 
-
Dec 10th, 2005, 12:44 PM
#12
Re: Program freezing [Resolved--Oddly]
Glad that you were able to track it down. Nice work
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|