How does one pass some parameters from the main thread to the working thread (ie the following procedure)?
Parallel.Async(
procedure (const task: IOmniTask)
begin
//How does one pass in 'myParam' from the main thread, so that the statement bellow will work?
s := task.Param['myParam'].AsString;
end
);
If you check the definition of IOmniTaskConfig (in OtlParallel.pas), there is a commented out property called Param, like the following:
// property Param: TOmniValueContainer read GetParam;
So I guess the answer to my question is no, but I wish it's not!
You are expected to use variable capture for this.
var
MyParam: Integer;
....
MyParam := 42;
Parallel.Async(
procedure(const task: IOmniTask)
begin
Foo(MyParam);
end
);
In case you are not familiar with variable capture for anonymous methods, it's discussed in some detail in the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With