unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TSysChatMainForm = class(TForm) procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } FTestNetThread: TThread; public { Public declarations } end; var SysChatMainForm: TSysChatMainForm; implementation {$R *.dfm} type TTestNetThread = class(TTHread) procedure Execute; override; procedure RefreshUIInMainThread; end; { TTestNetThread } procedure TTestNetThread.RefreshUIInMainThread; begin bsTrayIcon.ShowBalloonHint('网络异常','由于网络异常,程序掉线!',bsbitInfo); end; procedure TTestNetThread.Execute; begin inherited; FreeOnTerminate := True; while (not Terminated) and (not InternetGetConnectedState(nil, 0)) then begin Data.UserOff('[脱机]',false); Synchronize(RefreshUIInMainThread); Sleep(3000) end; end; { TSysChatMainForm } procedure TSysChatMainForm.FormCreate(Sender: TObject); begin FTestNetThread := TTestNetThread.Create(False); end; procedure TSysChatMainForm.FormDestroy(Sender: TObject); begin FTestNetThread.Terminate; end; end.
delphi 多线程定时执行程序如何写
最新推荐文章于 2024-01-04 14:36:04 发布