Création d'un callback de tâche (task)
De Wiki1000
(Différences entre les versions)
Ligne 14 : | Ligne 14 : | ||
Function Execute():boolean; | Function Execute():boolean; | ||
Procedure RegisterCallBack; | Procedure RegisterCallBack; | ||
+ | Procedure UnRegister; | ||
end; | end; | ||
Ligne 56 : | Ligne 57 : | ||
if not SubscribeToEvent(TTestTask.OnTerminateSuccessID(),aReason) then | if not SubscribeToEvent(TTestTask.OnTerminateSuccessID(),aReason) then | ||
showMessage('subscribe failed '+aReason); | showMessage('subscribe failed '+aReason); | ||
+ | end; | ||
+ | |||
+ | Procedure TestTaskCallBack.UnRegister; | ||
+ | //Procedure UnRegister; | ||
+ | var aReason:string; | ||
+ | begin | ||
+ | if not UnSubscribeFromEvent(TTestTask.OnTerminateSuccessID(),aReason) then | ||
+ | showMessage(aReason); | ||
end; | end; | ||
Version actuelle en date du 29 mars 2020 à 14:59
Un callback de tâche est une tâche déclenchée par la fin de l'exécution d'une autre tâche.
Exemple :
unit TestSYFREWF; interface Type TestTaskCallBack = Class(TitTask) public Function Execute():boolean; Procedure RegisterCallBack; Procedure UnRegister; end; Implementation {TestTaskCallBack} Function TestTaskCallBack.Execute():boolean; //Function Execute():boolean; var idx:Integer; S:string; aMsg:TdbmQueueMessage; begin Result := True; // Add messages to the log ProgressMessage('On TestTask Terminate'); if Assigned(UserContext.TaskContext) and Assigned(userContext.TaskContext.EventContext) then begin userContext.TaskContext.AddMessage('Has Task context'); // aMsg := userContext.TaskContext.EventContext.ReceivedMsg; if Assigned(aMsg) then begin userContext.TaskContext.AddMessage(Format('Task reference: %s',[aMsg.ValueByNames(':message.source.reference')])); userContext.TaskContext.AddMessage(Format('Message parameters count:%d',[aMsg.Count])); for idx:=0 to aMsg.Count-1 do begin S := aMsg.DisplayStrings(idx); UserContext.TaskContext.AddMessage(S); end; end; end else ProgressMessage('no task context'); Result := True; end; Procedure TestTaskCallBack.RegisterCallBack; //Procedure RegisterCallBack; var aReason:string; begin if not SubscribeToEvent(TTestTask.OnTerminateSuccessID(),aReason) then showMessage('subscribe failed '+aReason); end; Procedure TestTaskCallBack.UnRegister; //Procedure UnRegister; var aReason:string; begin if not UnSubscribeFromEvent(TTestTask.OnTerminateSuccessID(),aReason) then showMessage(aReason); end; end.