1

I am working on an add-in with multiple task panes. One of the task panes makes multiple HTTP requests to fetch data from a server and populate the worksheet.

When there is more than one task pane open, if I close the pane that fetches data from the server (and keeps another pane open), the worksheet updates as if the fetching pane is still open. Moreover, if I close the second pane, the worksheet keeps updating.

I thought that it related to SharedRuntime (https://learn.microsoft.com/en-us/office/dev/add-ins/develop/configure-your-add-in-to-use-a-shared-runtime) so I've disabled it but it didn't solve the issue.

I tried to catch events for the pane close/hide (https://learn.microsoft.com/en-us/office/dev/add-ins/develop/show-hide-add-in) in order to stop the worksheet from being updated - couldn't get events to fire.

I also tried to catch the beforeunload event. (How to capture the browser window close event?) also dead end - didn't work.

I thought it is somehow related to the network activity so I've managed to reproduce the issue with only local activity - just by running this function from the pane:

   function intervalUpdateCells() {
      setInterval(() => {
        var values = [
            [Math.floor(Math.random() * 1000), Math.floor(Math.random() * 1000), Math.floor(Math.random() * 1000)],
            [Math.floor(Math.random() * 1000), Math.floor(Math.random() * 1000), Math.floor(Math.random() * 1000)],
            [Math.floor(Math.random() * 1000), Math.floor(Math.random() * 1000), Math.floor(Math.random() * 1000)]
        ];
    
        // Run a batch operation against the Excel object model
        Excel.run(function (ctx) {
            var sheet = ctx.workbook.worksheets.getActiveWorksheet();
            sheet.getRange("B2:D4").values = values;
            sheet.getRange("B1:D1").values = [['A', 'B', 'C']];
            return ctx.sync();
        })
        .catch(errorHandler);
      }, 100);
    };

So if I run this function (it updates the active worksheet 10 times a second) from pane A while there are panes A & B open. when I'll close pane A the worksheet will continue to update and when I'll close pane B (and have no pane open) the worksheet will keep on updating.

My question: How can I detect that a task pane was closed in order to stop the worksheet from being updated?

EDIT: This is a very basic project that demonstrates the problem: https://github.com/YossiCohen/office-js-pane-not-closing-bug

yossico
  • 3,421
  • 5
  • 41
  • 76
  • Are you working on desktop Excel or Excel on the web? If it is the latter, note that your task panes are iFrames, not windows. The window is the whole Excel on the web tab. The runtime will not close until the entire window is closed. – Rick Kirkham Feb 10 '23 at 18:16
  • Why do you have/need multiple Task Panes Open? You mention a "fetching taskpane"? – FreeSoftwareServers Feb 10 '23 at 21:46
  • @RickKirkham This is Excel for desktop – yossico Feb 11 '23 at 18:12
  • @FreeSoftwareServers I have some ribbon icons, in the add-in, each icon does different functionality. There is an option that the user will open more than one taskpane – yossico Feb 11 '23 at 18:14

0 Answers0