0

i m facing a problem basically i have long running task that reads encoded bytes and then parse the bytes to find data in it.

  functionLongRunningTask() {
  //bytes returned from office.js (GetFileAsync Method)
  var documentText = OSF.OUtil.encodeBase64(resultSlice.value.data);

   // Open the document, which is stored as a base64 string.
   var doc = new openXml.OpenXmlPackage(documentText);
   var customXMLpart = doc.getPartByUri("/customXml/item1.xml");

    if (customXMLpart == 'undefined' || customXMLpart == null) {
     window.location = 'Page1.aspx'
      }
      else {
      if (window.DOMParser) {
       var parser = new DOMParser();
      xmlDoc = parser.parseFromString(customXMLpart.data, "text/xml");
       }
          var customxml = xmlDoc.getElementsByTagName("DocumentID");
             var documentid = 0;
        for (var i = 0; i < customxml.length; i++) {
               documentid = customxml[i].textContent;
                   }
            window.location = 'Page2.aspx?documentid=' + documentid;
                      }
  }

all of reading and traversing done on client side no server side involved in it. now as my application running in office word 2013 (Office APP basically) when i run this long Running task in synchronous way . UI gets freezed and stop responding and it restart Office APP.

i need to do it in Asynchronous way so UI dont get freeze i am using HTML5 and IE 9+. Any help will be appreciated

Regards

1 Answer 1

1

You wont have access to the DOM Parser in a WebWorker, so this method is not applicable. You will need to run portions of the code on a timer event.

Here is a library that may be able to help with running code against a timer -> https://github.com/jameswestgate/taskjs

Sign up to request clarification or add additional context in comments.

4 Comments

cant we have something like Callback . var doc = new openXml.OpenXmlPackage(documentText); when this method gets completed it sends callback then i can access DOM Parser
OK. So the problem is in the implementation of OPenXmlPackage? Can you confirm this in the debug window?
basically i try to read all bytes using var doc = new openXml.OpenXmlPackage(documentText); then i traverse var customXMLpart = doc.getPartByUri("/customXml/item1.xml"); and if i find something then i set window.location so the method that halts UI is var doc = new openXml.OpenXmlPackage(documentText); and its halts when document bytes are more than 50 kb and there is no bug in openxmlpackage just it takes time and that time halts UI that push office app to refresh itself
You could open this in a worker then send message the markup back to the main (UI) thread - yes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.