[Lazarus] custom thread reading file does not respond properly

Andrea Mauri andrea.mauri.75 at gmail.com
Wed Sep 6 16:59:32 CEST 2017


2017-09-06 16:26 GMT+02:00 el es via Lazarus <lazarus at lists.lazarus-ide.org>
:

>
> Can you try ThreadSwitch after Sleep ?
>
> while (not Terminated) do
>     begin
>       if eof(f) then
>         reset(f);
>       ReadLn(f, newStatus);
>       if NewStatus <> fStatusText then
>       begin
>         fStatusText := newStatus;
>         //Queue(@ShowStatus);
>         Synchronize(@Showstatus);
>         Sleep(5);
>         ThreadSwitch; /// <<<<
>       end
>       else  // also you need to cover what happens in ANY OTHER outcome of
> any test, e.g.
>         ThreadSwitch;
>       // because if NewStatus = fStatusText, you will IMMEDIATELY jump to
> the first instruction of the thread
>       // so adding the ThreadSwitch at the very end of the loop, you give
> the rest of the application (the main thread) a chance to
>       // actually do anything
>     end;
>
> Thread.Execute will execute ALL THE TIME if you don't yield/threadswitch
> in some code path, and WILL saturate your CPU.
>
>
Actually using sleep(1) I can interact with my application. ThreadSwitch
does not introduce any change. If I use sleep(1) it works, if I don't use
it but I use Yield or ThreadSwitch I cannot interact with my application.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20170906/4cc81d31/attachment.html>


More information about the Lazarus mailing list