Sometimes it works from terminal many times in a row for me.
Ok, finally after doing 25 times ./project1, enter, alt_f4, up, enter, alt_f4, up, enter, alt_f4 I finally had it hang on terminal too. But via the file-explorer it usually hangs the 1st through 4th time.
I've tried some things (dummy thread-initialization, CheckSynchronize()) but couldn't pin down why this would happen. But this goes beyond my ability to debug.
Even removing FreeOnTerminate and doing this makes it hang:
procedure TForm1.FormCreate(Sender: TObject);
var
t :TThread1;
begin
t := TThread1.Create(false);
t.WaitFor;
t.Free;
end;
In that case your thread is already ended when the form resumes creating.
It still hangs with a blank form.
(So I'm wondering if it's really your "busy" thread that's at fault or something else.
Even this makes it hang after enough times (so without running a thread):
procedure TForm1.FormCreate(Sender: TObject);
var
t :TThread1;
begin
//t := TThread1.Create(false);
//t.WaitFor;
//t.Free;
end;
So it might be just a general problem which the thread makes worse.
Edit: Even starting a form with one button without the cthreads in the uses of the project, the project hangs after about 25 starts from the file-explorer.
Edit #2: Now even after 1 or 2 starts. Seems like 64bit Lazarus is really unstable.
Simple example of a button starting the same executable and exiting.
Press the button a few times and see it hang.
(How does it work for you?)
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls, ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
uses Process;
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
AProcess: TProcess;
begin
AProcess := TProcess.Create(nil);
AProcess.Executable:= ParamStr(0);
AProcess.Execute;
AProcess.Free;
Close;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
end.