web
You’re offline. This is a read only version of the page.
close
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();
}

I have the same question (0)
  • Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    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)?

  • MikeBRoss Profile Picture
    on at
    [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.

  • Suggested answer
    MikeBRoss Profile Picture
    on at

    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.

  • Verified answer
    ergun sahin Profile Picture
    8,826 Moderator on at

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 646 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans