Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

VB6 Finalize Thread Pool on Program Exit (or Crash)

See more Async Examples

VB6 programs must call FinalizeThreadPool on exit if using any Async methods.

If your code is calling asynchronous Chilkat methods (i.e. methods having names ending with "Async"), then it is necessary to call FinalizeThreadPool when your program is about to exit. The VB6 IDE will crash unless all background threads are cleanly terminated.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Global;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  glob: TGlobal;

begin
  //  Asynchronous Chilkat methods are run in background threads managed
  //  by a thread pool manager thread, which is also a background thread.
  //  Prior to exiting, it is required in VB6 to ensure all asynchronous methods
  //  have completed or are aborted/cancelled, and that the thread pool manager
  //  thread is also shutdown.  
  //  
  //  The FinalizeThreadPool method should be called just before the application exits
  //  to ensure all background threads, including the thread pool manager thread, are
  //  cleanly shutdown.

  //  This is how to do it:
  glob := TGlobal.Create;
  glob.FinalizeThreadPool();


  glob.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.