[Lazarus] Message Loop paused when no interaction with mouse?

Bernd prof7bit at googlemail.com
Mon May 2 20:14:02 CEST 2011


2011/5/2 Michael Schnell <mschnell at lumino.de>:

> PostMessage() and QueueAsyncCall() _should_ work.

PostMessage() works (that is what I currently use) and
QueueAsyncCall() did not work when I opened this thread, I will test
it again tomorrow.

But what I would need for my application is something like
Synchronize(), I need to block my camera thread after every frame
until the GUI has updated itself with the newly received frame.
Therefore I have now re-implemented the functionality of Synchonize()
in the following way:

    // normally I would have used Synchoize() here but this
    // does not work with the really old GTK2 I have here anymore,
    // it would not wake up the GUI thread until I move the mouse.
    // The following 3 lines together with the message method in the
    // main form do exactly the same. It wakes up the GUI thread and
    // waits until it is done.
    RTLeventResetEvent(GuiHasFinishedEvent);
    PostMessage(Application.MainForm.Handle, MM_FRAME_COMPLETE, 0, 0);
    RTLeventWaitFor(GuiHasFinishedEvent);


and in the GUI

TMainForm = Class(TFom)
   ...
   procedure OnCameraFrame(var Msg); message MM_FRAME_COMPLETE;
   ...
end;

procedure TMainForm.OnCameraFrame(var Msg);
begin
  // it is alaways in updating state, only release this for a short moment
  Display.Picture.Bitmap.EndUpdate();
  Display.Picture.Bitmap.BeginUpdate();

  // the camera thread is waiting, notify it that we are done.
  RTLeventSetEvent(GuiHasFinishedEvent);
end;

This works like a charm.




More information about the Lazarus mailing list