delphi 多线程定时执行程序如何写
转载自:https://blog.csdn.net/chinajobs/article/details/51461368
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.