VB.NET Progress status while run a EXE file
Visual Basic
21
Posts
3
Posters
0
Views
1
Watching
-
Thanks, David. After I remove calling WaitForExit() and ReadToEnd(), the progressbar works now, but the Exited event function OnProcesited is not called, so the progressbar is always shown. How can I make OnProcesited() be called?
Private Sub OnProcesited(ByVal sender As Object, ByVal e As System.EventArgs)
Dim p As System.Diagnostics.Process
p = senderDim rtnStr As String = String.Empty rtnStr = p.StandardOutput.ReadToEnd() If rtnStr.Contains(" FAST terminated normally.") = True Then rtnStr = rtnStr & vbCrLf & "Please click Postprocess -> View Output File in menu to view the file." updateViewMenu() End If progBarFrm.Close() progBarFrm.Dispose() Dim frm As New FormShowFASTResult frm.txtFASTResult.Text = rtnStr frm.Button1.Select() frm.ShowDialog() End Sub Private Sub Run\_Tool() Dim sAppPath As String = ".\\XXXXX.exe" Dim fileName As String = "XXXXX.txt" Dim p As New System.Diagnostics.Process() p.StartInfo.FileName = Application.StartupPath & "\\" & sAppPath p.StartInfo.Arguments = fileName 'Do not use the system shell to start the program this is so we can hide the command dos window p.StartInfo.UseShellExecute = False p.StartInfo.WorkingDirectory = strOutputFilePath ' Show no dos window if false p.StartInfo.CreateNoWindow = True p.StartInfo.RedirectStandardOutput = True p.EnableRaisingEvents = True AddHandler p.Exited, AddressOf OnProcesited progBarFrm = New FormProgressBar Try p.Start() progBarFrm.Show() progBarFrm.Refresh() Catch ex As Exception ShowValidationMessage("Unexception error is caught, please close and try again.", "Error") Return End Try
End Sub
You can't force it. Your external process just hasn't stopped yet for some reason. Does your external process wait for the user to "Press any key to exit"?? I sure hope not!
A guide to posting questions on CodeProject[^]
Dave Kreskowiak