Jump to content
RaelB

Application does not close

Recommended Posts

I have a VCL app, running on Windows 10, Delphi 10.3.2.

 

Sometimes when I press the X button on the main form (to exit the app), the application does not close. The Main window disappears, however the IDE continues in "Running mode" / Debug Mode, i.e. the Program Reset button continues to be Red. When I press the Red button, the program then terminates completely and normally. Not too much going on in the application. What could be causing the program execution to hang in this way? How can I go about trying to figure out the cause? (I have no OnClose or OnCloseQuery handlers)

 

Thanks

Rael

Share this post


Link to post

You may have hidden some exception (Empty except block in a try/except). You may have a thread still running. You may have an issue in a finalization section of any unit. And many others.

Did you tried running under the debugger?

 

Share this post


Link to post

Instead of terminating the application in the debugger you can pause it and then examine the call stack to see what the application was doing.

Share this post


Link to post
1 hour ago, FPiette said:

You may have a thread still running.

Not necessarily a thread (the application will close anyway), but a task:

 

procedure TForm1.Button1Click(Sender: TObject);
begin
	TThread.CreateAnonymousThread(
		procedure()
		begin
			while true do;
		end
	).Start();
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
	TTask.Run(
		procedure()
		begin
			while true do;
		end
	);
end;

The application will close fine after Button1 has been clicked. The executable, however, will never terminate after closing the main form if Button2 was pressed.

Share this post


Link to post

It also can be that the application is generating a memory leak log when ReportMemoryLeaksOnShutdown := True it can take longer whene there is an extended leak to report.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×