D
Dave Taylor
I'm writing an app in VB.NET that provides a user-interface to computer
simulation model that runs as a console process. I would like to have the
console output redirected to my VB.NET program and I've done so with the
attached code. The problem is, redirecting its output slows down the code
severely. The code that starts the process is launched on its own thread,
so it doesnt completely stop the interface, but the time the model takes to
run is 8x or 10x longer than running the model directly from the command
line. I thought it would be smart to have the interface program wait awhile
before reading the output, so I tried using the Thread.Sleep command,
however, because of blocking this only exacerbated the problem. Ideally,
the output would fill a textbox as it runs...but I need some pointers on how
to write this code so that it doesnt block the executing process.
Thanks
Dave Taylor
Public Sub RunPhysica()
Dim phyProcess As Process, si As ProcessStartInfo
Dim sd As System.Collections.Specialized.StringDictionary
Dim srOut As System.IO.StreamReader
Dim srErr As System.IO.StreamReader
Dim sz As String
btnRun.Enabled = False
btnOk.Enabled = False
If ckWriteGeo.Checked Then _sim.GenerateGeometry(ckCompileGeo.Checked)
If ckWriteInf.Checked Then _sim.GenerateInform(ckCompileInf.Checked)
phyProcess = New Process
si = phyProcess.StartInfo
si.FileName = App.ColumnSimulations.PhysicaExec
si.UseShellExecute = False
si.WorkingDirectory = App.WorkingDirectory
sd = si.EnvironmentVariables
sd.Add("FGVKEY", App.GetSetting("PhysicaKeyFile", "C:\Program
Files\Femsys\KeyFile"))
si.RedirectStandardOutput = True
si.RedirectStandardError = True
tbRun.SelectedTab = tbpOutput
phyProcess.Start()
srOut = phyProcess.StandardOutput
srErr = phyProcess.StandardError
sz = String.Empty : txOutput.Text = ""
While Not sz Is Nothing
sz &= srOut.ReadLine
End While
txOutput.Text = sz
txErrors.Text = srErr.ReadToEnd
btnOk.Enabled = True
btnRun.Enabled = True
End Sub
simulation model that runs as a console process. I would like to have the
console output redirected to my VB.NET program and I've done so with the
attached code. The problem is, redirecting its output slows down the code
severely. The code that starts the process is launched on its own thread,
so it doesnt completely stop the interface, but the time the model takes to
run is 8x or 10x longer than running the model directly from the command
line. I thought it would be smart to have the interface program wait awhile
before reading the output, so I tried using the Thread.Sleep command,
however, because of blocking this only exacerbated the problem. Ideally,
the output would fill a textbox as it runs...but I need some pointers on how
to write this code so that it doesnt block the executing process.
Thanks
Dave Taylor
Public Sub RunPhysica()
Dim phyProcess As Process, si As ProcessStartInfo
Dim sd As System.Collections.Specialized.StringDictionary
Dim srOut As System.IO.StreamReader
Dim srErr As System.IO.StreamReader
Dim sz As String
btnRun.Enabled = False
btnOk.Enabled = False
If ckWriteGeo.Checked Then _sim.GenerateGeometry(ckCompileGeo.Checked)
If ckWriteInf.Checked Then _sim.GenerateInform(ckCompileInf.Checked)
phyProcess = New Process
si = phyProcess.StartInfo
si.FileName = App.ColumnSimulations.PhysicaExec
si.UseShellExecute = False
si.WorkingDirectory = App.WorkingDirectory
sd = si.EnvironmentVariables
sd.Add("FGVKEY", App.GetSetting("PhysicaKeyFile", "C:\Program
Files\Femsys\KeyFile"))
si.RedirectStandardOutput = True
si.RedirectStandardError = True
tbRun.SelectedTab = tbpOutput
phyProcess.Start()
srOut = phyProcess.StandardOutput
srErr = phyProcess.StandardError
sz = String.Empty : txOutput.Text = ""
While Not sz Is Nothing
sz &= srOut.ReadLine
End While
txOutput.Text = sz
txErrors.Text = srErr.ReadToEnd
btnOk.Enabled = True
btnRun.Enabled = True
End Sub