gpt4 book ai didi

delphi - 如何处理数据库应用程序的 sleep 模式网络丢失

转载 作者:行者123 更新时间:2023-12-03 14:48:24 25 4
gpt4 key购买 nike

我有几个 Delphi 程序维护与数据库的连接(一些是 Oracle,一些是 Firebird)。如果程序在 Windows 进入休眠模式时运行,则与数据库的连接就会丢失。处理这种情况的最佳方法是什么?有没有办法在网络进入休眠模式之前接收事件,以便我可以尝试更好地处理这种情况?

最佳答案

要详细说明 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;

关于delphi - 如何处理数据库应用程序的 sleep 模式网络丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10984612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com