By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,333 Members | 1,022 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,333 IT Pros & Developers. It's quick & easy.

how do I use a background thread for this?

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
* bl*****@yahoo.com (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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2

P: n/a
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
///
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.