2013-06-05 76 views
1

我做了一个应用程序,我们公司用来启动数据库并在需要时在用户机器上更新它们。缓慢应用程序的进程启动和错误

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

截至目前抛出的错误是:系统找不到指定的文件

我试图以防止这样的情况下,这种异常日志记录(慢速应用程序),但仍允许伐木如果一个真正的打开数据库时发生错误。

目前代码我使用:

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 

堆栈跟踪:

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 

回答

0

也许我失去了一些东西,但你为什么不干脆省略记录,如果你发现,特定的例外?

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 
+0

我想过这个,但并不想打折抛出相同信息但不是出于同样原因的真实错误。 – famousKaneis

+0

您也可以匹配异常类型来确保。 –

+0

毕竟,我最终采用这种方法,谢谢。 – famousKaneis