Skip to content

Commit

Permalink
Try and clean up more in powerpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vittala committed Oct 9, 2018
1 parent 1bca237 commit 1369590
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 8 additions & 3 deletions OfficeToPDF/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,19 @@ public static int Convert(String inputFile, String outputFile, Hashtable options
return (int)ExitCode.UnknownError;
}

// Clean up COM objects
/// <summary>
/// Clean up COM objects
/// </summary>
/// <param name="obj">COM object to be released</param>
/// <remarks>
/// See https://support.microsoft.com/en-gb/help/317109/office-application-does-not-exit-after-automation-from-visual-studio-n
/// </remarks>
protected static void ReleaseCOMObject(object obj)
{
try
{
if (null != obj && System.Runtime.InteropServices.Marshal.IsComObject(obj))
while (null != obj && System.Runtime.InteropServices.Marshal.ReleaseComObject(obj) > 0)
{
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
}
}
catch { }
Expand Down
7 changes: 7 additions & 0 deletions OfficeToPDF/PowerpointConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,18 @@ class PowerpointConverter : Converter
throw;
}
}
finally
{
ReleaseCOMObject(printType);
ReleaseCOMObject(quality);
}
} else
{
// Print via a delegate
PrintToGhostscript((string)options["printer"], outputFile, printFunc);
}
ReleaseCOMObject(printType);
ReleaseCOMObject(quality);

// Determine if we need to make bookmarks
if ((bool)options["bookmarks"])
Expand Down

0 comments on commit 1369590

Please sign in to comment.