我有一个名为TextBox1的TextBox,它由一个使用OpenFileDialog获取文件路径的Button填充。我想要一个按钮(Button3)以2小时的间隔一个接一个地启动几个进程然后关闭它并打开下一个进程。
总共我有4个不同的TextBoxes(TextBox1,TextBox2,TextBox3和TextBox4)和4个不同的文件路径,我想用同一个按钮打开我之前提到的间隔。
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
OpenFileDialog1.Title = "Please Select a File"
OpenFileDialog1.InitialDirectory = "C:temp"
OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
Dim strm As System.IO.Stream
strm = OpenFileDialog1.OpenFile()
TextBox1.Text = OpenFileDialog1.FileName.ToString()
If Not (strm Is Nothing) Then
'insert code to read the file data
strm.Close()
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
OpenFileDialog2.Title = "Please Select a File"
OpenFileDialog2.InitialDirectory = "C:temp"
OpenFileDialog2.ShowDialog()
End Sub
Private Sub OpenFileDialog2_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog2.FileOk
Dim strm As System.IO.Stream
strm = OpenFileDialog2.OpenFile()
TextBox3.Text = OpenFileDialog2.FileName.ToString()
If Not (strm Is Nothing) Then
'insert code to read the file data
strm.Close()
End If
End Sub
Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
End Sub
End Class
答案 0 :(得分:0)
要启动新流程,请使用:
dim myProcess = Process.start(filename)
你没有'需要执行以下操作的代码:
Dim strm As System.IO.Stream
strm = OpenFileDialog2.OpenFile()
If Not (strm Is Nothing) Then
strm.Close()
End If
这是打开exe文件,就像它试图从中读取数据一样。
而只是使用
dim process = Process.Start(OpenFileDialogX.Filename)
注意:您的初始目录似乎是c:temp而不是c:\ temp,因为它可能应该是