none
call of documents.open slow in addIn RRS feed

  • Question

  • following I can't understand:

    case A:

    Instanciating Word with 'app= CreateObject( "Word.Application"); docs=app.Documents' in an EXTERNAL APPLICATION (.exe, here Delphi).

    case B:

    in a Word-AddIn (dll) I got the Application-Instance by "OnConnection( app:IDispatch);
    also getting docs= app.Documents

    ----------------------

    then in both cases I measure the time needed for identical call to open the same document:

    //tm= now

    doc= docs.Open( FileName:= ..., ConfirmConversions:= false, ReadOnly:= True, AddToRecentFiles:= false)

    // diff = now-tm

    -----------------------

    in both cases variables "docs" and "doc" are variants and in both I used late binding - exact the same code line.

    Now I would expect, case B should be much faster because COM calls should be inside process and no time loss because of process sceduling as in case A (to Switch from Delphi .exe to WinWord and back)

    but the opposite of expected occures:

    case A needs only about 250 ms, case B needs about 350 ms, and because I must open hundred thousands of files (from time to time), this is a very expensive loss of time.

    please what can be the reason of that behaviour ?

    Wednesday, September 6, 2017 1:31 PM

All replies

  • Hi Bu-Updated,

    Do you develop Word-Addin by C# or C++? In my option, it is no meaning to compare the open time between Delphi and Word-AddIn, they are complier and running on different languages. And CreateObject to create new word instance is still different from Word-in which will invoke current word instance. Their working mechanisms are not same either.

    Do you want to open documents in Word-Addin? What do you want to do with hundred thousands files? In my option, if you open such many files, will not your word be no responding?

    We usually use Word Addin to provide functions for end user to interop with Word. Could you share us the reason you need to open thousands files in Word AddIn? We may try to check whether there is any other option for you.

    More information about your requirements would be helpful.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 7, 2017 8:45 AM
  • Hi Edward,

    thanks for the reply.
    the reason is simple the same problem, thousands of developer have: Word to PDF conversion.

    (just for your information: we developed our own compiler lile a basic-similiar language, which generates thousands of documents based on a rtf-template, database-connectors and so on as input and pdf-documents as output; generation of the document needs about 20 seconds up to 5 minutes. our clients are spoilt to get-just-in-smallest-time, but the problem is to convert the docs to pdf because if each document needs about 500 ms-1 sec then process needs 1,4 - 2,8 hours. also for new clients we have sometimes to convert millions of old documents.

    and definitly NO, SharePoint can't be used because converting is embedded in complex processes and also our clients will not introduce SharePoint because of all the overhead, technical and human resources needed just only to convert documents to pdf, sry.

    and although we create different processes as SharePoint for converting; that's not the problem. but all the tests has been done just in a single test program with only 1 word and there seems to be a bottleneck in word which prevents the "as fast as possible").

    the addin is developed in Delphi, but Delphi itself needs for execute that single line just about some µs and the compiled assembler code of that single line "docs.Open(...)" is exactly the same as in the word addin.

    ONLY this line of code has been measured in both cases, nothing else, only with getting start time before and after  (original delphi-code in both cases, program and addin):

    ------------

      tm:= now;

      _doc:= _docs.Open(

               FileName:=    a_src_File,
               ConfirmConversions:= false,
               ReadOnly:=    True,
               AddToRecentFiles:= false
            );

      diff:= now - tm;

    --------------

    so, 350ms : 250ms is about 50% more if executed in the addin, that's a lot. can this be a threading problem (in word; because my addin doesn't create additional threads by itself) ? does IDTExtensibility2 some additional overhead, but instanciating from external binds a more performant interface ? some ideas ?

    Best Regards

    Adalbert


    • Edited by bu-Updated Thursday, September 7, 2017 2:29 PM
    Thursday, September 7, 2017 2:25 PM
  • Hi bu-Updated,

    >>can this be a threading problem (in word; because my addin doesn't create additional threads by itself) ?

    To check whether multiple threads work for you, I suggest you create new threads to open new Word application and then convert the files to pdf. You could try initializing multiple threads the same time.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 8, 2017 1:49 AM