Correct flow stop at OmniThreadLibrary



  • Created. Task Library OmniThreadLibrary♪ When calling method FTask.Terminate - The job stops, but will it be correct?

    Maybe there's some other way to tell us to do the team. Terminate and check in the flow if Terminated then Exit?

    TSomeClass = Class
    Private 
     FEventMonitor: TOmniEventMonitor;
     FTask: IOmniTaskControl;
    public 
      procedure Start;
      procedure Stop;
    End;
    

    Constructor TSomeClass.Create;
    Begin
    FEventMonitor := TOmniEventMonitor.Create(Nil);
    End;

    procedure TSomeClass.Start;
    var
    Task: IOmniTaskControl;
    begin
    Task := CreateTask(SomeProc, 'Some task');
    FTask := FEventMonitor.Monitor(Task).Run;
    end;

    procedure TSomeClass.Stop;
    begin
    If Assigned(FTask) Then
    FTask.Terminate(2000);
    end;

    Procedure TSomeClass.SomeProc(Сonst Task: IOmniTask);
    begin
    ....
    end;



  • In this library, you can send a signal (FTask.CancellationToken.Signal) to the stop and inside check this signal or not as follows:

    Procedure TSomeClass.SomeProc(Сonst Task: IOmniTask);
    begin
        ...
        if Task.CancellationToken.IsSignalled then
            Exit;
        ...
    end;
    

    procedure Stop;
    begin
    If Assigned(FTask) Then
    FTask.CancellationToken.Signal;
    end;




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2