Recent

Author Topic: What is way to set timeouts on TProcess running in threads and output to GUI?  (Read 3785 times)

vfclists

  • Hero Member
  • *****
  • Posts: 1165
    • HowTos Considered Harmful?

What is the good way to execute programs running in threads, set time outs on them and pass whatever output has been received so far to a GUI?

These are my thoughts on the matter:

1.  the timeout: each process has its own timer. The timer fires to kill the process and the thread, but whatever output must be

2. the output: It appears that the standard way judging from the wiki is to wait for the process to complete before the output is displayed. From the example here - http://wiki.freepascal.org/Executing_External_Programs#Reading_large_output - would it be okay to use the Synchronize method pass whatever is output to the GUI output is read?

Lazarus 3.0/FPC 3.2.2

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
I think that's good enough. What I've ever made is only using a combination of Sleep(1), Now() and MilliSecondSpan(). Code:
Code: [Select]
StartTime := Now;
while Process.Running and (MilliSecondSpan(StartTime,Now) < Threshold) do Sleep(1);
// at this point, either the process has died or the time is out

 

TinyPortal © 2005-2018