Display Progress Bar while Executing Dos Process

MorrisPS

Member
Joined
Jul 29, 2008
Messages
5
Programming Experience
10+
Hello everyone, what i am trying to accomplish is execute a dos command with the following code:
frmStatusBar.Show()
' Set start information.
Dim start_info As New ProcessStartInfo(sOutput)
With start_info
.UseShellExecute = False
.CreateNoWindow = True
.RedirectStandardOutput = True
.RedirectStandardError = True
.WorkingDirectory = Exec_Path
.Arguments = sParam
End With

' Make the process and set its start information.
Dim proc As New Process()
proc.StartInfo = start_info
proc.EnableRaisingEvents = True


frmOutput.txtOutput.Text = ""
frmOutput.txtCommand.Text = ""
frmOutput.txtError.Text = ""

frmOutput.txtCommand.Text = sOutput & " " & sParam

' Start the process.
proc.Start()

' Attach to stdout and stderr.
Dim std_out As StreamReader = proc.StandardOutput()
Dim std_err As StreamReader = proc.StandardError()

' Display the results.
frmOutput.txtOutput.Text = std_out.ReadToEnd() & vbCrLf
frmOutput.txtError.Text = std_err.ReadToEnd() & vbCrLf

Application.DoEvents()

' Clean up.
std_out.Close()
std_err.Close()
proc.Close()

If Len(Dir(Exec_Path & "\eboot.pbp")) = 0 Then
ExecuteDOS = False
Exit Function
End If

frmStatusBar.Close()
ExecuteDOS = True

and then display a progressbar while it is executing so that the user does not think that the app is locked up.
 
In that case I suggest that you create a form that has a ProgressBar on it with the Style set to Marquee. You can open this form as a modal dialogue and provide no way to close it for the user. In that form you would create a new Process to run your commandline app. You can handle the Exited event of that Process and then call Close on your dialogue.
 
They're two completely separate processes. The ProgressBar would only not move if you called WaitForExit and blocked your UI thread until the process ended. If you handle the Exited event then you won't block your UI thread.
 
Back
Top