vb.net - 进程启动和应用程序运行缓慢导致的错误

标签 vb.net process error-handling

我制作了一个应用程序,供公司启动数据库,并在需要时在用户计算机上更新数据库。

在启动数据库和数据库启动缓慢时,我遇到了一个小问题。当发生这种情况时,我的应用程序将引发异常,因为我假设它正在等待某种响应。

到目前为止,抛出的错误是:系统找不到指定的文件

我试图在这种情况下阻止这种异常日志记录(慢速应用程序),但如果打开数据库时发生实际错误,仍然允许进行日志记录。

我正在使用的当前代码:

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/

相关文章:

javascript - 在 Office 加载项中启用扩展错误日志记录(查看错误对象的完整说明)

.net - 转换 Skip LINQ 方法结果的正确方法

vb.net - 如何在 VB.net 2010 Express 中使用 Windows API 代码包?

mysql - 使用相同打开的连接插入超过 50 个查询

c - 父进程等待所有子进程完成后再继续

java - 获取在后台运行的 Java 运行时进程

linux - 如何在Linux中说明使用较小的进程nice值?

python-3.x - 错误处理函数的有效方法

具有多个项目的 ASP.NET Gridview 模板字段

error-handling - 如何处理来自reqMktData调用的错误