1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
uses OtlCommon,OtlParallel,OtlEventMonitor,OtlTask,OtlTaskControl,OtlComm;
//主线程中的消息处理
procedure TForm1.OmniEventMonitor1TaskMessage(const task: IOmniTaskControl;
const msg: TOmniMessage);
begin
case msg.MsgID of
1:ClientDataSet2.Open;
2:Label1.Caption := 'start';
3:Label1.Caption :='end';
4:Label1.Caption := 'sleep';
end;
end;
//任务创建
procedure TForm1.Button5Click(Sender: TObject);
begin
FTASK:=OmniEventMonitor1.Monitor(CreateTask(GetAll,'GetAll')).Run ;
end;
//任务体
procedure GetAll(const task:IOmniTask); //参数必须是这样子
var
aa:TClientRuleClient;
f:OleVariant;
begin
task.Comm.Send(2,'start');
Form1.ClientDataSet2.Close;
aa:=TClientRuleClient.Create(Form1.SQLConnection1.DBXConnection);
f:= aa.GetAll;
FreeAndNil(aa);
Form1.ClientDataSet2.Data := f;
task.Comm.Send(4,'sleep');
Sleep(3000);
task.Comm.Send(3,'end');
task.Comm.Send(1,'task terminated');
end;
|