Just moved a project to Delphi 12, an entire thread appears to not be working

procedure MonitorFile(const AID: Integer; const AFileDate: TDateTime; const AFilename: String);
begin
  TThread.CreateAnonymousThread(
    procedure
    var
      Doc: TDocuments;
      t: Extended;
    begin
      while (GetFileModifiedDate(AFilename) = AFileDate) or (Application.Terminated) do
      begin
        t := Now;
        repeat
          sleep(10);
        until (now - t > 100) or Application.Terminated;
      end;
      if (GetFileModifiedDate(AFilename) <> AFileDate) then
      begin
        Doc := TDocuments.Create(Nil);
        try
          if Doc.Load(AID) then
          begin
            Doc.DocImage.LoadFromFile(AFilename);
            Doc.Save(False);
          end;
        finally
          Doc.Free;
        end;
      end;
    end
  );
end;

Any idea why this wouldn’t work? It runs fine in 11.3.
In Delphi 12, I can’t step into it and the thread doesn’t run at all as far as I can see.

I don’t see why it would work in Delphi 11.3 - you’re not calling Start on the thread you’re creating

3 Likes

Doh! Homer moment…
I Messed that up somehow, it used to work…

1 Like