Création d'un callback de tâche (task)
De Wiki1000
Version du 29 mars 2020 à 14:59 par Syfre (discuter | contributions)
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.