By re-initialize, I mean stop the running tasks (or even kill the threads if I have to) & revert back as if the pipeline/threads were never initialized / started.
My code (I'm using delphi 2010, OmniThreadLibrary 3.02) looks like this:
procedure SomeProc();
var
AFile : TOmniValue;
begin
APipeline := Parallel.Pipeline.NumTasks(5).Stage(StageProc).Run;
AFile.CreateNamed(['FileID', FileID, 'FileName', FileName]);
MyPipeline.Input.Add(AFile);
end;
// --------------- //
procedure StageProc(const Input, Output : IOmniBlockingCollection; const Task : IOmniTask);
begin
// ...
end;
I need something like this:
// --------------- //
procedure ResetPipeline();
begin
// Stop any task running inside StageProc() & reset pipeline, ie.
KillTasks(pipeline);
pipeline := nil;
end;
Notes
FWIW, yes, I'm fully aware that this is really a bad idea!
I'm also well aware that the best approach would be to send a stop signal to tasks and wait for them to nicely shutdown, and check often for stop signals inside tasks. I'm not interested in that for this very particular case.
Although the code above only mention pipelines, a solution to reset BackgroundWorker would be enough for me.
Thanks in advance!