Skip to content

Commit

Permalink
Alter how we close Word
Browse files Browse the repository at this point in the history
  • Loading branch information
vittala committed Jan 10, 2018
1 parent 5f015c0 commit 8564c0f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion OfficeToPDF/ExcelConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ protected static void setPageSetupProperties(Hashtable tps, PageSetup wps)
}
}

protected static bool closeExcelWorkbook(Workbook workbook)
private static bool closeExcelWorkbook(Workbook workbook)
{
int tries = 20;
while (tries-- > 0)
Expand Down
4 changes: 2 additions & 2 deletions OfficeToPDF/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.8.6.0")]
[assembly: AssemblyFileVersion("1.8.6.0")]
[assembly: AssemblyVersion("1.8.7.0")]
[assembly: AssemblyFileVersion("1.8.7.0")]
22 changes: 21 additions & 1 deletion OfficeToPDF/WordConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,32 @@ class WordConverter: Converter
}
if (word != null && !running)
{
((_Application)word).Quit(ref oMissing, ref oMissing, ref oMissing);
closeWordApplication(word);
}
Converter.releaseCOMObject(word);
}
}

// Try and close Word, giving time for Office to get
// itself in order
private static bool closeWordApplication(Application word)
{
object oMissing = System.Reflection.Missing.Value;
int tries = 20;
while (tries-- > 0)
{
try
{
((_Application)word).Quit(ref oMissing, ref oMissing, ref oMissing);
return true;
}
catch (COMException)
{
Thread.Sleep(500);
}
}
return false;
}
// We want to be able to reset the options in Word so it doesn't affect subsequent
// usage
private class AppOption
Expand Down

0 comments on commit 8564c0f

Please sign in to comment.