我已经看到了一些类似的问题,但我希望这不是一个重复的问题。我正在使用这里找到的FO.NET项目:https://fonet.codeplex.com/从我的VB.NET应用程序中生成PDF文件。
Fonet.dll
和Fonet.exe
文件都包含在应用程序中,我这样称呼它:
Public Sub FormatObjectToPdf(intRxNo As Integer, strSourceFileName As String)
Dim startInfo As New ProcessStartInfo
Dim strPdfFile As String = StrRootPath & "Paperwork\" & intRxNo & "M.pdf"
' if the PDF file already exists, no need to re-create it
If Not File.Exists(strPdfFile) Then
Try
startInfo.Arguments = "-fo """ & strSourceFileName & """ -pdf """ & strPdfFile & """"
startInfo.FileName = StrAppPath & "FO.NET\fonet.exe"
startInfo.UseShellExecute = True
startInfo.WindowStyle = ProcessWindowStyle.Hidden
Using proc As Process = Process.Start(startInfo)
proc.WaitForExit()
If proc.HasExited Then
proc.Dispose()
End If
End Using
Catch ex As Exception
Call InsertLog("ErrorLog", "FormatObjectToPdf: " & ex.Message, ex)
MessageBox.Show(ex.Message, "Create PDF", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End If
' wait 3 seconds to allow file to be released
Threading.Thread.Sleep(3000)
' delete the source FO file when processing is complete
If File.Exists(strSourceFileName) Then
Try
File.Delete(strSourceFileName)
Catch iEx As IOException
Call InsertLog("ErrorLog", "[IOException]: Could Not delete file '" & strSourceFileName & "': " & iEx.Message)
Catch ex As Exception
Call InsertLog("ErrorLog", "Error deleting file '" & strSourceFileName & "': " & ex.Message, ex)
End Try
End If
End Sub
我的问题是,进程偶尔会失败,并且会弹出一个未处理的异常,Fonet.exe
应用程序将崩溃(而不是调用应用程序)。如果我重新运行完全相同的呼叫,它通常会起作用。它只是偶尔发生,但似乎越来越频繁。有没有办法从外部程序中捕获异常进行调试?或者其他一些方法来查看导致崩溃的原因,以便我可以尝试修复它?