我制作了一个应用程序,供公司启动数据库,并在需要时在用户计算机上更新数据库。
在启动数据库和数据库启动缓慢时,我遇到了一个小问题。当发生这种情况时,我的应用程序将引发异常,因为我假设它正在等待某种响应。
到目前为止,抛出的错误是:系统找不到指定的文件
我试图在这种情况下阻止这种异常日志记录(慢速应用程序),但如果打开数据库时发生实际错误,仍然允许进行日志记录。
我正在使用的当前代码:
Private Sub OpenApplication()
If File.Exists(LocalPathString) Then ' File Found. Open the File.
Try
Dim ps As New Process
ps = Process.Start(LocalPathString)
Catch ex As Exception
ex.Source += " | " & LocalPathString
RaiseEvent ShowError(ex)
Finally
RaiseEvent CancelIt() ' Thread Complete. Close the ActionForm
End Try
Else
If LocalPathString = vbNullString Then
RaiseEvent CancelIt() ' No file exits. Cancel thread.
Else
RaiseEvent ShowError(New Exception("Database Not Located: " & LocalPathString))
End If
End If
End Sub
StackTrace:
System.Diagnostics.Process.StartWithShellExecuteEx(startInfo As ProcessStartInfo)
App.exe: N 00912
System.Diagnostics.Process.Start()
App.exe: N 00136
System.Diagnostics.Process.Start(startInfo As ProcessStartInfo)
App.exe: N 00049
SAMi.ActionClass.OpenApplication()
App.exe: N 00117
最佳答案
也许我缺少了一些东西,但是如果发现了特定的异常,为什么不简单地省略日志记录呢?
Catch ex As Exception
ex.Source += " | " & LocalPathString
if not ex.Message.Contains("The system cannot find the file specified") Then
RaiseEvent ShowError(ex)
end if
关于vb.net - 进程启动和应用程序运行缓慢导致的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16940182/