Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

SysExcelApplication is leaving background processes

(0) ShareShare
ReportReport
Posted on by

Hello, I currently have a class for exporting to excel certain forms/grids for which the base excel export is disabled (such as the Period grid on Net Requirements). I am calling application.quit() on my SysExcelApplication object, which is closing out the workbook and the open process (under 'Apps' in Task Manager). Unfortunately it is leaving open a background excel process taking up ~36MB of memory. Not a big deal on its own, but every time the class is run it leaves another such background process, which could have more serious performance concerns. Oddly if I start excel normally from windows and close it, it never opens a background process. 

Is there something else I should be doing to close out the process other than calling the quit() method? Walking through the debugger doesn't help much because the quit method code just calls itself and the debugger can't go into it (I am assuming it is calling the method on the excel COM object or something that the ax debugger doesn't have access to).

This is my code for reference:

protected void exportToExcel(FormDataSource _formDataSource)
{
    SysExcelApplication     excelApplication    = SysExcelApplication::construct();
    SysExcelWorkbooks       workBooks           = excelApplication.workbooks();
    SysExcelWorkbook        workBook            = workBooks.add();
    SysExcelWorkSheets      workSheets          = workbook.worksheets();
    SysExcelWorkSheet       workSheet           = workSheets.add();
    Filename                filename;
    #Macrolib.Excel;

    excelApplication.visible(false);

    filename = this.getFilename();
    if (!filename)
    {
        excelApplication.quit();
        return;
    }

    this.insertData(workSheet, _formDataSource);

    excelApplication.displayAlerts(false);
    workBook.saveAs(filename, #xlWorkbookDefault);
    excelApplication.quit();
}

  • Verified answer
    ergun sahin Profile Picture
    8,816 Moderator on at
    RE: SysExcelApplication is leaving background processes

    I edited my answer from "Close workbooks" --> "close workbook/workbooks" but apparently I deleted it completely

  • Suggested answer
    MikeBRoss Profile Picture
    on at
    RE: SysExcelApplication is leaving background processes

    For some reason the reply by Ergun Sahin that fixed my issue is not displaying for me in the thread, so I will add it here and mark it as solved until I can see his post.

    Adding a call to close out the workbook and workbooks and recompiling solved the processes stubbornly staying open.

  • MikeBRoss Profile Picture
    on at
    RE: SysExcelApplication is leaving background processes
    [quote]

    What do you mean by the background process? What is its name?

    Don't you just mean that the memory is still allocated (not that a process keeps running)?

    [/quote]

    I may be using the wrong terminology, my apologies for that. What I am seeing that worries me is, when I open the Task Manager, under the processes tab under 'Background Processes', there is an 'Excel' there that is using a bit of memory. Every run of the class will leave another 'Excel' here after it's done. These were not closing themselves and would just stack up unless manually killed in task manager.

    Image

    Ergun Sahins suggestion seems to have done the trick though (or at least coincided with it fixing itself) and the processes are now closing and not hanging open.

  • Martin Dráb Profile Picture
    231,923 Most Valuable Professional on at
    RE: SysExcelApplication is leaving background processes

    What do you mean by the background process? What is its name?

    Don't you just mean that the memory is still allocated (not that a process keeps running)?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,238 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,923 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans