Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Shutting down your Microsoft Office application can seem tricky to get right at first, but once you establish the correct order of operations, it's actually not very hard at all. </p> <p>Releasing your MS Office application can be done safely and effectively in two stages:</p> <p>(1) First release all the minor objects to which you do not hold a reference within a named variable. You do this via a call to <a href="http://msdn.microsoft.com/en-us/library/system.gc.collect.aspx" rel="nofollow noreferrer">GC.Collect()</a> and then <a href="http://www.bing.com/search?setlang=en-US&amp;mkt=en-US&amp;q=gc.waitforpendingfinalizers" rel="nofollow noreferrer">GC.WaitForPendingFinalizers()</a> . Note that if you are using Visual Studio Tools for Office (VSTO), then you need to call this pair of commands <strong>twice</strong> in order to get the COM objects to successfully release. You are not using VSTO, however, so calling them once is sufficient.</p> <p>(2) Then explicitly release the objects which you hold via a named variable using a call to <a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.finalreleasecomobject.aspx" rel="nofollow noreferrer">Marshall.FinalReleaseComObject()</a> on each variable you have. </p> <p>Remember to explicitly release <strong>all</strong> variables that you have to COM components. If you miss even one, then your MS Office application will hang. In your code, you seem to have three named variables that hold a reference to your PowerPoint application: <code>ppApp</code>, <code>ppPres</code>, and <code>cell</code>.</p> <p>Taking this all into account, I think that your cleanup should look something like the following, which makes use of <code>using System.Runtime.InteropServices</code> either within the namespace or at the top of the code document:</p> <pre><code>// using System.Runtime.InteropServices // Cleanup: GC.Collect(); GC.WaitForPendingFinalizers(); Marshal.ReleaseComObject(cell); ppPres.Close(); Marshal.ReleaseComObject(ppPres); ppApp.Quit(); Marshal.ReleaseComObject(ppApp); </code></pre> <p>Give it a try, I think this should work for you... (If not, you might have to show even more of your code.) For further information, I give a detailed explanation on how to properly release an Excel application here: </p> <p><a href="https://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects-in-c/159419#159419">How to properly clean up Excel interop objects in C#</a>.</p> <p>Hope this helps, let us know how it goes...</p> <p>-- Mike</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload