-1
我已經寫了一些代碼來檢查,如果一個進程正在運行,如果它不然後運行可執行文件。編譯錯誤:BC30203:預期標識符。 MyBase.load
我如何過得到一個錯誤如下:
編譯錯誤:BC30203:標識符。
代碼如下任何人都可以幫忙嗎?
Imports System.IO
Public Class Form1
Private P As Process
Private FileName As String = "C:\Program Files\D-Tech\MultiSelfCheck\D-Tech.SelfCheck.FormApplication.exe"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim ps() As Process = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(FileName))
If ps.Length = 0 Then
P = Process.Start(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, (FileName)))
P.EnableRaisingEvents = True
AddHandler P.Exited, AddressOf P_Exited
Else
P = ps(0)
P.EnableRaisingEvents = True
AddHandler P.Exited, AddressOf P_Exited
End If
End Sub
Private Sub P_Exited(sender As Object, e As EventArgs)
Console.WriteLine("App Exited @ " & DateTime.Now)
Console.WriteLine("Restarting app: " & FileName)
P = Process.Start(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, (FileName)))
P.EnableRaisingEvents = True
AddHandler P.Exited, AddressOf P_Exited
End Sub
End Class
不是100%肯定,但也許你不應該有在論據的Process.Start周圍的變量括號?它需要一個字符串參數。與Path.Combine一樣。 –
哪一行給出錯誤? –
我複製了你的代碼並嘗試了它......它似乎在我的環境中完美工作。請注意,我將目標FileName更改爲「C:\ Program Files(x86)\ Notepad ++ \ notepad ++。exe」。 8 – Squidx3