none
word compare feature - Revisions.Count vs Revisions.getEnumerator? Microsoft.Office.Interop RRS feed

  • Question

  • Hi,

    We are trying to compare two documents and in the process of code returns Microsoft.Office.Interop.Word.Revisions.Count as 900, but when I get Microsoft.Office.Interop.Word.Revisions.GetEnumerator and looping through it, its running more than 7500 items and also each one takes around 40 secs to 1 min.

    The compare service was hosted in Windows 2012 server with .net framework 4.0 version installed. 

    1) I m not sure why there is difference between Revisions.Count and Revision.GetEnumerator() collection count?

    2) also, not sure why it is taking more time read each Iteration?

    Advance thanks for your suggestion?

    Thanks,

    Vel


    Wednesday, February 5, 2014 4:03 PM

Answers

  • Hello Murugavel,

    1. The Revisions class from the Word object model doesn't provide the GetEnumerator method. Actually, it is a feature provided by the .Net framework for allowing you to use the foreach loop.

    2. Most probably you don't release underlying COM objects instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release a Word object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. You can read more about this in the Systematically Releasing Objects article in MSDN. Though it is related to Outlook, the same can be applied to Word.

    Also I'd recommend using the for loop instead of the GetEnumerator or the foreach loop.

    Finally, Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    You can find available workarounds described in the Considerations for server-side Automation of Office article.



    Wednesday, February 5, 2014 7:48 PM

All replies

  • Hello Murugavel,

    1. The Revisions class from the Word object model doesn't provide the GetEnumerator method. Actually, it is a feature provided by the .Net framework for allowing you to use the foreach loop.

    2. Most probably you don't release underlying COM objects instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release a Word object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. You can read more about this in the Systematically Releasing Objects article in MSDN. Though it is related to Outlook, the same can be applied to Word.

    Also I'd recommend using the for loop instead of the GetEnumerator or the foreach loop.

    Finally, Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    You can find available workarounds described in the Considerations for server-side Automation of Office article.



    Wednesday, February 5, 2014 7:48 PM
  • Thanks Eugene, You reply was helpful why the count is different between Revisions.count and GetEnumerator(), I m trying with openXML approach suggested.

    Thanks,

    Murugavel

    Thursday, February 6, 2014 11:22 AM