Wait for threads in console application lazarus / 61-Beginners ---------------------------------------------------------------------- tudi_x · 2018-06-24 10:24 hi All, what is the best way to wait for threads in a console application? i am using a _hasRun global variable, but is this the best option? thank you 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 program gogs_console; {$mode objfpc}{$H+} uses {$IFDEF UNIX}  cthreads, {$ENDIF}  Classes,  SysUtils,  unidac10,  pgprovider10,  CustApp,  postgres_connect,  get_repos_urls; type  TGogsConsole = class(TCustomApplication)  protected    _hasRun: boolean;    procedure DoRun; override;   public    constructor Create(TheOwner: TComponent); override;    destructor Destroy; override;     procedure CatchRepoURLs(ARepoList: array of string);  end;   procedure TGogsConsole.DoRun;  var    c: TPostgresConnInfo;    h: TCreateDBHandler;    r: TGogsRepos;   begin    if not _hasRun then    begin      c.ServerIP := '192.168.1.46';      c.ListenPort := 5432;    c.Username := 'gogs';      c.Password := 'gogs';      c.Database := 'gogs';       h := TCreateDBHandler.Create(c);      writeln('connected:' + BoolToStr(h.IsConnected, True));       r := TGogsRepos.Create(h.DBConnection, h.DBTransaction);      r.OnPassResults := @CatchRepoURLs;       WriteLn('xxx');       _hasRun := True;    end;  end;   constructor TGogsConsole.Create(TheOwner: TComponent);  begin    _hasRun := False;     inherited Create(TheOwner);    StopOnException := True;  end;   procedure TGogsConsole.CatchRepoURLs(ARepoList: array of string);  var    i: word;   begin    for i := Low(ARepoList) to High(ARepoList) do    begin      WriteLn('TGogsConsole.CatchRepoURLs:' + ARepoList[i]);    end;     Terminate;  end;   destructor TGogsConsole.Destroy;  begin  inherited Destroy;  end; var  Application: TGogsConsole; begin  Application := TGogsConsole.Create(nil);  Application.Title := 'GOGS Console';  Application.Run;  Application.Free;end. (Lazarus 1.8.4 64b, Linux MINT)