I have some apps that run daily, from 8 am to 8 pm, non-stop.
Sometimes these computers go to sleep and since the app is still open and I’m using MS SQL (means I’m connected with my app to SQL server), when PC comes out of sleep, app hangs and needs to be killed manually.
How do you guys deal with this? Is there a way to forcefully close the app (when it’s somewhere with some form open, it’s the worst, I know) before going into sleep? Or do you prevent sleep with your app?
Best would be if app would “survive” this sleep/wakeup as if nothing has happened but…
Brilliant strategy, albeit involving a fair amount of extra SQL traffic reading column definitions on each new thread. I’ve used this in several SQL-based web apps that now run reliably for months at a time.
The basic premise is to use a unique connection string per thread. You can use the application name parameter of the connection string to accomplish this. The when each thread closes, it disconnects from the server. That way open connections are not kept forever. I’ve only used this solution in server/service programs.
However, you are describing the user leaving the browse or update form open and then the computer is going into sleep mode. That’s different. Unfortunately, I don’t think you are going to find a good resolution. Clarion just does not handle a lost connection to the server very well.
One way would be to have your program prevent Sleep.
I’ve done it by using the API Keybd_Event() to send Keyboard Events that just press and release the Shift key. The GetLastInputInfo() API lets you check if the user has not done anything for X minutes and then press Shift.
I have some code that uses Capesoft’s WinEvent and Windows messages to help detect when the computer goes into sleep mode and when it wakes. That, along with the other suggestions, may help you. I’ll post the code when I get to my dev machine.
case Event() - WinMessageEvent
of 0 ! WinMessageEvent
! Start of "WinAlert Message Processing"
! [Priority 2500]
Of PBT_APMPOWERSTATUSCHANGE !Power status has changed.
Of PBT_APMRESUMEAUTOMATIC !Operation is resuming automatically from a low-power state. This message is sent every time the system resumes.
Of PBT_APMRESUMESUSPEND !Operation is resuming from a low-power state. This message is sent after PBT_APMRESUMEAUTOMATIC if the resume is triggered by user input, such as pressing a key.
Of PBT_APMSUSPEND !System is suspending operation.