我有几个 Delphi 程序维护与数据库的连接(一些 Oracle,一些 Firebird。)如果程序在 Windows 进入睡眠模式时运行,则与数据库的连接将丢失。处理这种情况的最佳方法是什么?有没有办法在网络进入睡眠模式之前接收事件,以便我可以尝试更好地处理这种情况?
问问题
2558 次
1 回答
6
要详细说明 RRUZ,您需要以下内容:
procedure WMPowerBroadcast(var AMessage: TMessage); message WM_POWERBROADCAST;
以你的形式。然后WMPowerBroadcast
会是这样的:
procedure TMyForm.WMPowerBroadcast(var AMessage: TMessage);
const
PBT_APMSUSPEND = 4;
PBT_APMRESUMESUSPEND = 7;
begin
case AMessage.WParam of
PBT_APMSUSPEND:
begin
// save your DB stuff. NOTE: IIRC you are pretty limited in the time
// you get to do this - 2 seconds ? may be the limit
end;
PBT_APMRESUMESUSPEND:
begin
// restore your DB connection
end;
else
// you're going to want to handle PBT_APMRESUMECRITICAL (XP and older systems) and PBT_APMRESUMEAUTOMATIC differently
// IIRC you did not get notification of the suspend in this case
end;
end;
于 2012-06-11T20:24:22.207 回答