how do I use a background thread for this?

  • Thread starter Thread starter Antonio Policelli
  • Start date Start date
A

Antonio Policelli

Cheers!
I have a sub like this
sub runProgram(programName as striing, programPath as string)
....
End sub

the sub will run another exe from within my applicaiton. I don't need
to return anything to my application, I just need to run execute the
sub on a background thread so my applicaiton remains responsive. all
I have to do is pass in these 2 strings. can someone show me the code
to do this?

AP
 
* (e-mail address removed) (Antonio Policelli) scripsit:
I have a sub like this
sub runProgram(programName as striing, programPath as string)
...
End sub

the sub will run another exe from within my applicaiton. I don't need
to return anything to my application, I just need to run execute the
sub on a background thread so my applicaiton remains responsive. all
I have to do is pass in these 2 strings. can someone show me the code
to do this?

Not sure, but why not use 'Shell' or 'System.Diagnostics.Process.Start'
without a new thread? The function will return immediately after
starting the other application.
 
Hi Antonio,

When you start that exe with process.start it is already on his own thread,
there is nothing needed to add.

I give you some samples beneath

I hope this helps,

Cor

\\\simple word start
Dim p As New System.Diagnostics.ProcessStartInfo()
p.Verb = "print"
p.WindowStyle = ProcessWindowStyle.Hidden
p.FileName = "C:\filename.doc"
p.UseShellExecute = True
System.Diagnostics.Process.Start(p)
///
\\\notepad with text from WinIni
Dim p As New Process
p.StartInfo.UseShellExecute = True
p.StartInfo.Arguments = "c:\windows\win.ini"
p.StartInfo.FileName = "notepad.exe"
p.Start()
///
\\\Regedit
Dim p As Process = New Process
Dim p As ProcessStartInfo = New ProcessStartInfo
p.FileName = "regedit"
p.Arguments = "/S C:\yourRegFile.reg"
p.StartInfo = p
p.Start()
///
\\\Start with getting the output from the console in your program
Dim p As New Process
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.Arguments = myargumentstring
p.StartInfo.WorkingDirectory = myworkdirectorystring
p.StartInfo.FileName =C:\myprogram
p.Start()
Dim sr As IO.StreamReader = p.StandardOutput
Dim sb As New System.Text.StringBuilder("")
Dim input As Integer = sr.Read
Do Until input = -1
sb.Append(ChrW(input))
input = sr.Read
Loop
///
 
Back
Top