[RESOLVED] Windows Threaded console app issue? lazarus / 8-Other ---------------------------------------------------------------------- DGambrinus · 2009-05-08 14:28 Hello all. I've recently had to port a Linux app to the Windows world for work and I'm running into an annoyance. This app is a console app that runs threads every now and again and it would seem that once you create a thread in a FPC console app that the explorer shortcut (Windows+E) doesn't work until the application is killed. (Other Windows key shortcuts work though. Win+R, Win+D) Before the thread is launched it works great. If you hit Win+E after the thread is launched nothing happens except your taskbar/start menu doesn't respond to anything. When the app closes your taskbar/start menu comes back and then you do get the number of explorer windows corresponding to the number of times you pressed "Win+E". I've tested on a few machines (all WinXP as that is the target environment) and it seems to be consistent. Just wondering if I am doing something dumb or if I should submit a bug report. The same code in Delphi doesn't have the same issue. FPC: 2.2.2 Lazarus: 0.9.26 OS: WinXP fully patched. Here is code for a test app. This app just counts to ten, launches a thread that stays alive for 8 seconds, and then closes 2 seconds after that. Win+E works up until the thread is launched at second 10 and doesn't work until the app closes at 20 seconds. Code: [Select]//------------------------------------------------------ -------------------------------------------------------------------- program project1; {$mode objfpc}{$H+} uses   {$IFDEF UNIX}{$IFDEF UseCThreads}   cthreads,   {$ENDIF}{$ENDIF}   Classes, sysutils   { you can add units after this }; type   { TDummyThread }   TDummyThread = class(TThread)   private   protected     procedure Execute; override;   public     constructor Create;   end; { TDummyThread } procedure TDummyThread.Execute; var   i: Integer; begin   i := 0;   while i < 8 do   begin     Sleep(1000);     inc(i);   end;   WriteLn('Thread terminated!');   self.Terminate(); end; constructor TDummyThread.Create; begin   Self.FreeOnTerminate := True;   inherited Create(True); end; var   i: Integer;   t: TDummyThread; begin   i := 0;   while i < 20 do   begin     if (i < 10) then       Writeln('Starting thread in ' + inttostr(10 - i) + ' seconds...')     else if (i = 10) then     begin       WriteLn('Starting thread! Does WIN+E work?);       t := TDummyThread.Create();       t.Resume();     end     else       WriteLn('Closing in ' + inttostr(20 - i) + ' seconds.');     Sleep(1000);     inc(i);   end; end. //-------------------------------------------------------------------- ------------------------------------------------------ Thanks for any insight. --Sam ---------------------------------------------------------------------- clauslack · 2009-05-10 02:01 With Application.ProcessMessages works, but only in LCL/FreePascal Application Maybe FreePascal not process messages from Windows. Look at this (form.pas), with a Memo and Button unit form; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, LResources, Forms, Controls, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)     Button1: TButton;     Memo1: TMemo;     procedure Button1Click(Sender: TObject);   private     { private declarations }   public     { public declarations }   end;  TDummyThread = class(TThread)   private   protected   procedure Execute; override;   public    constructor Create;   end; var   Form1: TForm1; implementation { TForm1 } procedure TDummyThread.Execute; var  i: Integer; begin   i := 0;   while i < 8 do    begin      Sleep(1000);      inc(i);      Application.processmessages;    end;   // WriteLn('Thread terminated!');    self.Terminate(); end; constructor TDummyThread.Create; begin   Self.FreeOnTerminate := True;   inherited Create(True); end; procedure TForm1.Button1Click(Sender: TObject); var   i: Integer;   t: TDummyThread; begin   i := 0;   while i < 20 do   begin     if (i < 10) then       memo1.lines.add('Starting thread in ' + inttostr(10 - i) + ' seconds...')     else if (i = 10) then     begin       memo1.lines.add('Starting thread! Does WIN+E work?');       t := TDummyThread.Create();       t.Resume();     end     else    memo1.lines.add('Closing in ' + inttostr(20 - i) + ' seconds.');     Sleep(1000);     Application.processmessages;     inc(i); end; end; initialization   {$I form.lrs} end. ---------------------------------------------------------------------- DGambrinus · 2009-05-11 11:55 Thanks for looking into it, Clauslack! Yes, LCL apps seem to work fine. I can't think of anything that the end user actually needs to know about this app so I don't have a GUI. I may post as a FPC bug and see what they say. I just don't know if it is a FPC thing or a Windows thing. ---------------------------------------------------------------------- DGambrinus · 2009-05-11 17:48 I submitted this as a potential bug to the FPC folks. (Issue # 0013688 in the bug tracker.) It has been fixed in the compiler version 2.3.1 which is currently unstable. I recompiled with the new compiler and it has indeed fixed this issue. http://bugs.freepascal.org/view.php?id=13688