Recent

Author Topic: fpgApplication.ProcessMessages from a thread  (Read 3282 times)

dieselnutjob

  • Full Member
  • ***
  • Posts: 141
fpgApplication.ProcessMessages from a thread
« on: October 28, 2014, 11:39:43 pm »
I have a second thread which is a timer thread.  Basically it just does this
Code: [Select]
while (not Terminated) do
  begin
    Synchronize(@UpdateGui);
    sleep(100);
  end;

This causes some code to poll other stuff, in other threads, so that the gui can control them and update results etc.

The problem has been that occasionally this thread would not terminate.  I tracked it down (I think) to a procedure that was called by the polling thing which had an fpgApplication.ProcessMessages in it.

It seems that sometimes when the thread is terminated it just stalls on the fpgApplication.ProcessMessages rather than quitting out.  It never seems to cause a problem at any other time.

Can anyone shed any light on this?

Fred vS

  • Hero Member
  • *****
  • Posts: 1675
    • miXimum is the DJ's best friend
Re: fpgApplication.ProcessMessages from a thread
« Reply #1 on: October 29, 2014, 01:31:00 am »
Hello.

Have you try with queue() instead of synchronize() ? (but you need fpc 2.7.1)

I had some problem with  synchronize() and queue() does the work much better.

A other thread-safe (and very fast) method is to use the build-in fpGUI SentMessage().

Fre;D


   
I use Lazarus 1.8.0 32/64 and FPC 3.0.3 32/64 on Linux Mint Mate 17 32/64, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs