双线程问题
我想用一线程,控制加密狗,判断加密狗是否存在,主线程就是应用程序,当加密狗不存在时,弹出窗口...这要怎么实现,平时比较少接触线程,请指教,谢谢
[解决办法]
unit Unit2;
interface
uses
Classes;
type
aaa = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;
implementation
{ aaa }
procedure aaa.Execute;
begin
{ Place thread code here }
while true do
begin
.............
sleep(1000);
end;
end;
end.
[解决办法]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TDogCheckThread = class(TThread) //加密狗检测线程类
protected
procedure Execute; override;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TDogCheckThread.Execute;
begin
while not Terminated do
begin
//此处放上你检测加密狗的代码
(*
......
if 加密狗不存在 then
begin
......
end;
*)
sleep(1000);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
//创建加密狗检测线程的实例并运行
TDogCheckThread.Create(False);
end;
end.