John Dammeyer wrote:
> I've created a unit that has a thread that has a TTimer object that runs
> periodically to access an A/D converter.
>
>       AtoDThread := TAcquisitionThread.Create(FALSE);
>       AtoDThread.Priority := tpHigher;
>       AtoDThread.Resume; // now run the thread
>
> Inside the AtoDThread the Execute
>
>     DLPortIO :=  TDLPortIO.Create(nil);
>     DLPortIO.DriverPath := 'c:\DMT\Plotter'; // This is where we've
> installed it.
>
>     AtoDState := RESET_HARDWARE_STATE;
>     while not Terminated do
>       ;       // Do nothing but ideally suspend somehow while leaving
> the timer running.
>
> What I'd like to do is just have the Execute thread do nothing else other
> than let the timer fire which then gathers the data and fills appropriate
> variables etc.
>
> If I suspend the thread I believe it will also suspend the timer won't it?
> What's a better way to block the execute part of the thread while leaving
> the timer active?

Timers require a message pump, so you must be calling GetMessage somewhere
in that thread. GetMessage blocks until a message arrives, and that's
exactly what you're asking to do.

while not Terminated and (GetMessage(Msg, 0, 0, 0) > 0) do begin
  TranslateMessage(Msg);
  DispatchMessage(Msg);
end;

To improve responsiveness to setting the thread's Terminated flag, you
should provide a new Terminate method:

procedure AtoDThread.Terminate;
begin
  inherited;
  PostThreadMessage(ThreadID, wm_Null, 0, 0);
end;

That guarantees there's a message on the queue, causing GetMessage to
return. Otherwise, you need to wait for the next timer tick.

-- 
Rob


_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

Reply via email to