Page 1 of 1

[Dropped] AOO task still running after Delphi program terminates

Posted: Wed Sep 15, 2021 4:48 pm
by gavinsbtm
I'm writing a delphi 10.3 program and testing on Windows 10.

When I run the terminate command on a com.sun.star.frame.Desktop object, the office task remains running in the background and can be seen on the windows task manager. The following is the most simple version of the code i'm using to replicate this.

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  ooServiceManager, ooDesktop: Variant;

begin
  ooServiceManager := CreateOleObject('com.sun.star.ServiceManager');
  ooDesktop := ooServiceManager.CreateInstance('com.sun.star.frame.Desktop');
  ooDesktop.Terminate;
end;
I can force the task to terminate by sunning

Code: Select all

ShellExecute(0, nil, 'c:\windows\system32\taskkill.exe', '/F /iM soffice.bin', nil, SW_HIDE);
but that seems a bit hacky...

How do I terminate the office task using the service manager or desktop?

Re: Office task still running after delphi program terminate

Posted: Wed Sep 15, 2021 4:53 pm
by RoryOF
Possibly relevant discussion and methods at
viewtopic.php?f=20&t=73209

Re: Office task still running after delphi program terminate

Posted: Wed Sep 15, 2021 5:07 pm
by gavinsbtm
RoryOF wrote:Possibly relevant discussion and methods at
viewtopic.php?f=20&t=73209
I've tried looping through and closing any open docs - no joy.

It seems to happen even without creating an instance of com.sun.star.frame.Desktop.

The following code has the same result

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  ooServiceManager: Variant;
begin
  form1.caption := 'Started';

  ooServiceManager := CreateOleObject('com.sun.star.ServiceManager');

  ooServiceManager.dispose;

  form1.caption := 'Finished';
end;

Re: Office task still running after delphi program terminate

Posted: Fri Jan 14, 2022 2:03 pm
by Lupp
You sure that all the frames created by the desktop were closed and there can't be a veto?

Just for curiosity: What bridge did you use? Does it (or a variant of it) also work with FreePascal/Lazarus? Under different OS?


<edit>
Did you read viewtopic.php?f=5&t=40059 ?
</edit>