Mar*_*rkF 8 delphi networking delphi-xe2
我有几个Delphi程序来维护与数据库的连接(一些Oracle,一些Firebird.)如果程序在Windows进入睡眠模式时运行,则与数据库的连接将丢失.处理这种情况的最佳方法是什么?有没有办法在网络进入睡眠模式之前接收事件,这样我可以尝试更好地处理这种情况?
要详细说明RRUZ,您需要以下内容:
procedure WMPowerBroadcast(var AMessage: TMessage); message WM_POWERBROADCAST;
Run Code Online (Sandbox Code Playgroud)
在你的形式.然后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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2300 次 |
| 最近记录: |