2016-09-26 55 views
0

在我的應用程序中,我已經寫了這個子程序用於重新啓動我的程序。 這段代碼沒問題。重新啓動應用程序並檢查是否已在運行

Sub Restart 
    'For restart application many times 
    Application.Current.Shutdown() 
    System.Diagnostics.Process.Start(Application.ResourceAssembly.Location) 
End Sub 

過了幾天,我添加該代碼檢查程序已經運行。 (這個代碼是確定)

Sub IsRunning 
    'Check if it's already running 
    If (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1) Then 
     Msg = "Application is running" 
     MessageBox.Show(Msg, "Attention", MessageBoxButton.OK, MessageBoxImage.Error) 
     Application.Current.Shutdown() 
    End If 
End Sub 

現在,有什麼問題?如果我嘗試重新啓動應用程序,我收到消息「應用程序正在運行」,我不能這樣做!

如何解決這個問題?

非常感謝

回答

相關問題