none
Task Pane App restarts when large file is added to input control RRS feed

  • Question

  • Hello,

    My task pane app runs great when I use it to convert a file below a certain size. I tried to set a 2 MB file to the input control and Excel declared the App not responsive and it restarted my app. Is there anyway to extend the length of the time out?

    Here's my error:

    Thanks


    John Donnelly

    Monday, August 11, 2014 9:53 PM

Answers

  • Hi John,

    >> The block to the UI now that is causing a restart is the setting of a large string (>3.3 million characters) to a text area.

    I’m a little curious about your purpose to save a large string (> 3.3 million characters) to a text area, it is not a specific question for Apps for Office. Even for a normal web page, it will also cause a performance issue.

    >> Visual Studio is giving me a JavaScript Internal State error when is tries to construct the Blob. Is the File API supported?

    As I tested using the sample in my IE 11, it tell me “The Blob constructor is not supported”.

    To save the data locally, I will suggest you using Web Storage.

    Hope it will help.

    Regards,

    Jeffrey


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by J_Donnelly Thursday, August 21, 2014 3:49 PM
    Thursday, August 21, 2014 6:27 AM
    Moderator

All replies

  • Hi John,

    I failed to reproduce the issue, I can select the file which great than 2 MB file. As far as I know, the input control for the file doesn't submit the data unless we submit the form.

    Does this control works in a common web application? If yes, would you mind sharing us
    some code snippet to reproduce this issue?

    Best regards

    Fei



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, August 12, 2014 10:08 AM
    Moderator
  • Hi Fei,

    Thanks for the response.

    Yes I apologize there is code running in the input control's change event as follows:

     $('#baiInput').change(function(event) {
                    Window.fileChanged = true;
                    if (filesDone === 0) {
                        filesDone += 1;
                        startRead(event);
                        $('#baiInput').prop('disabled', true);
                    } else {
                        Office.context.document.settings.set("stopWelcome", true);
                        app.showNotification(Window.UIText.info, Window.UIText.inorderto);
                    }
                });

    In addition I compute a hash on the file in the following function chain:

    // Create FileReader Function
        function startRead() {
            // obtain input element through DOM
    
            var file = document.getElementById('baiInput').files[0];
            Window.filename = file.name;
            Window.filesize = file.size;
            Window.filetype = file.type;
            Window.lastmod = file.lastModifiedDate;
            if (file) {
                getAsText(file);
            }
        }
    
        function getAsText(readFile) {
            var reader = new FileReader();
    
            // Read file into memory
            reader.readAsText(readFile);
            //reader.onprogress = updateProgress;
            reader.onload = loaded;
            reader.onerror = errorHandler;
        }
    
        function loaded(evt) {
            try {
                // Obtain the read file data
                var baitext = evt.target.result;
                var obscText = obscure(baitext);
                Window.baitext = obscText;
                var baihash = window.hex_md5(obscText);
                Window.baihash = baihash;
            } catch (error) {
                app.showNotification(error);
            }
        }
    Do you think I need to move the hash function outside of the change event.

    Thanks


    John Donnelly

    Tuesday, August 12, 2014 3:43 PM
  • Hi John,

    As far as I know, JavaScript in Web Browser is executed by a single thread. If there are some complex computing (like MD5 Hash computing) blocking the execution, I think it will affect the response of App (as we can see from error message: sorry, we had to restart because this app wasn’t responding).

    Please try to remove the code to compute the MD5 hash so that we could narrow down this issue.

    For complex computing code, I suggest you using the JavaScript Worker which will start a new thread to compute.

    Hope it will help.

    Regards,

    Jeffrey


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by J_Donnelly Friday, August 15, 2014 2:35 PM
    • Unmarked as answer by J_Donnelly Friday, August 15, 2014 2:35 PM
    Thursday, August 14, 2014 7:54 AM
    Moderator
  • Thanks for the response Jeffrey.

    I put the code to compute the hash in a Worker thread and the control worked fine. However large files continue to cause problems. In particular, after fixing the hash computation the app is now being declared non-responsive after the AJAX call while setting content into textboxes. I read somewhere that if your UI interactions will take longer than 15ms one should have it done in a new thread.

    I don't believe I can use a Web Worker to interact with the DOM so I think I will have to research using deferreds. In addition because of the demands of large files I have some more optimization to do with the server side code.

    Anyway I won't mark an answer yet until I get back with something that works. If you can think of a way to make this process easier or better I would appreciate it.


    John Donnelly





    • Edited by J_Donnelly Saturday, August 16, 2014 7:44 PM
    Friday, August 15, 2014 1:46 PM
  • Hi John

    >> I don't believe I can use a Web Worker to interact with the DOM

    Yes, we could not manipulate the DOM from the background thread (Web Workers). But if you need to result in changes to the DOM, you could send a message to the creator by using postMessage method.

    var hello = new Worker('hello.js');
    hello.onmessage = function(e) {
      alert(e.data);
    };

    Regards,

    Jeffrey


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, August 18, 2014 7:02 AM
    Moderator
  • Thanks for the response Jeffrey. I've done all I can with Web Workers. The block to the UI now that is causing a restart is the setting of a large string (>3.3 million characters) to a textarea. It is not only the first setting of the textarea but every time the UI tab is selected it re-sets the textarea.

    I think that I would like to  instead download the text in a file to the client using msSaveOrOpenBlob method.

    Visual Studio is giving me an JavaScript Internal State error when is tries to construct the Blob. Is the File API supported?

    If not, can you recommend a best way to make the download happen?


    John Donnelly

    Tuesday, August 19, 2014 12:10 AM
  • Hi John,

    >> The block to the UI now that is causing a restart is the setting of a large string (>3.3 million characters) to a text area.

    I’m a little curious about your purpose to save a large string (> 3.3 million characters) to a text area, it is not a specific question for Apps for Office. Even for a normal web page, it will also cause a performance issue.

    >> Visual Studio is giving me a JavaScript Internal State error when is tries to construct the Blob. Is the File API supported?

    As I tested using the sample in my IE 11, it tell me “The Blob constructor is not supported”.

    To save the data locally, I will suggest you using Web Storage.

    Hope it will help.

    Regards,

    Jeffrey


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by J_Donnelly Thursday, August 21, 2014 3:49 PM
    Thursday, August 21, 2014 6:27 AM
    Moderator
  • Thanks for the response Jeffrey.

    >> I'm a little curious about your purpose to save a large string (> 3.3 million characters) to a text area, it is not a specific question for Apps for Office. Even for a normal web page, it will also cause a performance issue.

    I know, I was trying to make an XML snippet available to the user via a textarea and it worked great until I started testing the conversion of larger files using the app.

    My plan now is to turn the Xml text into a file and have it download for them.

    Thanks for your help.


    John Donnelly

    Thursday, August 21, 2014 3:49 PM