omnithreadlibrary

Getting a Delphi TTimer to work with a multi-threading app

回眸只為那壹抹淺笑 提交于 2019-12-05 21:05:37
I have an issue with a simple TTimer that's initiated and have its OnTimer event executed in the main app thread , the code looks like this: procedure TForm1.DoSomeStuff(); begin OmniLock.Acquire; try Parallel.Pipeline.NumTasks(MaxThreads).Stage(StageProc).Run; if (MyTimer = nil) then begin MyTimer := TTimer.Create(nil); MyTimer.Interval := 60 * 1000; // timer fired every 60 seconds MyTimer.OnTimer := MyTimerEvent; MyTimer.Enabled := True; end; finally OmniLock.Release; end; // try/finally end; Everthing work just fine when I execute the code in a simple project/demo, but in my app (which uses

Get a function result asynchronously in Delphi using Omni Thread Library

回眸只為那壹抹淺笑 提交于 2019-12-05 06:20:54
问题 I am trying to call a function from another unit/class which would take some time in performing the task and would return a string value. I couldn't find a good reference something similar to C# async-await like simple approach in Delphi. Using Omni Thread library seems a good idea for me. A simple example will be a great start for me. Sample approach: procedure TForm1.button1Click(Sender: TObject); begin // notify before starting the task memo1.Lines.Add('calling a asynchronous function..');

How to monitor Pipeline stages in OmniThreadLibrary?

↘锁芯ラ 提交于 2019-12-04 09:20:08
Is it possible to monitor Pipeline tasks somehow? I tried to add monitors to each task like this FPipeline := Parallel.Pipeline() .Stage(StageWorker1, Parallel.TaskConfig.MonitorWith(MyMonitor)) .NumTasks(MaxReadThreadCount) .Stage(StageWorker2, Parallel.TaskConfig.MonitorWith(MyMonitor)) .Run(); but getting the exception "Task can be only monitored with a single monitor" (as I understand, it happens because the internal hidden monitor is already installed for pipeline stages). Use Parallel.TaskConfig.OnMessage and provide a common message processing function. FPipeline := Parallel.Pipeline()

OmniThreadLibrary - Code: 1816. Not enough quota is available to process this command

我怕爱的太早我们不能终老 提交于 2019-12-01 20:16:25
问题 Update 1 : I included the stack traces of all threads instead of just the main thread's - I thought it was enough already. Update 2 : I reopened this question, since even after applied the changes illustrated in my own question, I still get the very same error report today... Update 3 : It seems that the error happened when the thread is terminating and the thread message that's being sent when the error happened was COmniTaskMsg_Terminated . Now it's very strange - I've replaced almost all

How to Stop all Pipeline tasks correctly

非 Y 不嫁゛ 提交于 2019-12-01 01:38:38
how to stop Pipleline tasks correctly, I've tried but when i press Abort button i get an AV, i'm not too good at debugging,i have reached to DoOnStop(task); in OtlParallel then i couldn't figure out what to do next, i believe there is something missing ? type procedure SetInProcess(const Value: Boolean); private FInProcess: Boolean; property inProcess: Boolean read FInProcess write SetInProcess; public FStopAll: Boolean; procedure FlushData; procedure Retriever(const input: TOmniValue; var output: TOmniValue); ... procedure TForm1.SetInProcess(const Value: Boolean); var I: Integer; begin if

Why is OmniThreadLibrary's ForEach blocking main thread?

丶灬走出姿态 提交于 2019-12-01 00:19:51
Using the OmniThreadLibrary and Delphi XE4, I am hoping to run multiple threads that process data in the background, adding speed increases to my already existing code. When calling the procedure below, the Application GUI stops processing any input until all of the threads have completed. My understanding is that using .NoWait should allow the procedure to exit even when the threads are running. procedure Test(input: TStringList; output: TList<TMaintFore>); var outQueue: IOmniBlockingCollection; transaction: TOmniValue; begin outQueue := TOmniBlockingCollection.Create; Parallel.ForEach(0,

How to Stop all Pipeline tasks correctly

筅森魡賤 提交于 2019-11-30 20:15:23
问题 how to stop Pipleline tasks correctly, I've tried but when i press Abort button i get an AV, i'm not too good at debugging,i have reached to DoOnStop(task); in OtlParallel then i couldn't figure out what to do next, i believe there is something missing ? type procedure SetInProcess(const Value: Boolean); private FInProcess: Boolean; property inProcess: Boolean read FInProcess write SetInProcess; public FStopAll: Boolean; procedure FlushData; procedure Retriever(const input: TOmniValue; var

Why is OmniThreadLibrary's ForEach blocking main thread?

倖福魔咒の 提交于 2019-11-30 19:13:17
问题 Using the OmniThreadLibrary and Delphi XE4, I am hoping to run multiple threads that process data in the background, adding speed increases to my already existing code. When calling the procedure below, the Application GUI stops processing any input until all of the threads have completed. My understanding is that using .NoWait should allow the procedure to exit even when the threads are running. procedure Test(input: TStringList; output: TList<TMaintFore>); var outQueue:

How to implement thread which periodically checks something using minimal resources?

南笙酒味 提交于 2019-11-30 12:07:20
I would like to have a thread running in background which will check connection to some server with given time interval. For example for every 5 seconds. I don't know if there is a good "desing pattern" for this? If I remember corretly, I've read somewehere that sleeping thread in its execute method is not good. But I might be wrong. Also, I could use normal TThread class or OTL threading library. Any ideas? Thanks. You could use an event and implement the Execute method of the TThread descendant by a loop with WaitForSingleObject waiting for the event, specifying the timeout. That way you can

How to implement thread which periodically checks something using minimal resources?

我的梦境 提交于 2019-11-29 17:24:35
问题 I would like to have a thread running in background which will check connection to some server with given time interval. For example for every 5 seconds. I don't know if there is a good "desing pattern" for this? If I remember corretly, I've read somewehere that sleeping thread in its execute method is not good. But I might be wrong. Also, I could use normal TThread class or OTL threading library. Any ideas? Thanks. 回答1: You could use an event and implement the Execute method of the TThread