[Solved] Linux application freezes lazarus / 32-Linux ---------------------------------------------------------------------- nikel · 2021-10-01 23:19 Hello, I created a multi threaded procedure, my buttons and grid is active. But when I press right top X the program can't close. Here's my code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Procedure TForm1.NormalizeAudio(Idx: Integer);Var  ...Begin  ...   AProcess := TProcess.Create(Nil);  Try    AProcess.InheritHandles := False;    AProcess.Options := [];    AProcess.ShowWindow := swoShow;     // Copy default environment variables including DISPLAY variable for GUI application to work    For I := 1 to GetEnvironmentVariableCount Do    AProcess.Environment.Add(GetEnvironmentString(I));     AProcess.Executable := '/bin/bash';    AProcess.Parameters.Add('-c');    AProcess.Parameters.Add('ffmpeg -y -i "' + SongPath^.OldPath + '" -filter:a loudnorm "' + SongPath^.TempSongPath + '"');    AProcess.Execute;  Finally    AProcess.Free;  End;   For Num:=0 To 4294967295 Do  Begin    If (AProcess.Active = True) Then Sleep(10) Else Begin ConvertAudio(QueueHandler^.CurrentIndex); NormalizeAudioUnset End;    Application.ProcessMessages;  End;End; I tried to add functionality to exit program by pressing Esc but it didn't work eighter. ---------------------------------------------------------------------- dbannon · 2021-10-02 02:23 Hmm, you are creating one TProcess and using it to launch multiple processes each in its own thread ? Are you sure that TProcess is thread safe ?  And if it is, my  guess is it would be only if you created the TProcess in its thread. Still guessing, is it safe to free that TProcess before all threads have finished ? Disclaimer - I have not tried any thing like what you are doing. Davo ---------------------------------------------------------------------- nikel · 2021-10-02 15:52 I know it's not a proper way of running external program in a queue. Once it run the queue alltogether. I think I have only 2 choice: To use a loop or call a function again and again. Am I right? ---------------------------------------------------------------------- Warfley · 2021-10-02 23:38 The form can only close after the main eventloop is called again through the event handler returns. Easy way to implement: add a variable/field Closed or similar and set it in the OnClose event handler to true. Then in your application.processmessages loop add another condition checking that the close wasnt called (by checking closed for false) and if that is the case exit the procedure. This will return to the main event loop and close the form PS wu do you count from 0 to maxint rather than having a While True loop? ---------------------------------------------------------------------- nikel · 2021-10-03 21:01 Thanks  for the reply. I'm going to try that. I didn't know about the "MaxInt". ---------------------------------------------------------------------- nikel · 2021-10-05 22:05 This worked fine: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i For Num:=0 To 4294967295 DoBegin  If (AProcess.Active = True) Then Sleep(10) Else Begin ConvertAudio(QueueHandler^.CurrentIndex); NormalizeAudioUnset End;  If (CloseRequest = True) Then Begin Break End;  Application.ProcessMessages;End;If (CloseRequest = True) Then Begin NormalizeAudioUnset; Close End; Thank you for your help.