PC Review


Reply
Thread Tools Rate Thread

how do I use a background thread for this?

 
 
Antonio Policelli
Guest
Posts: n/a
 
      15th Jul 2004
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
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      15th Jul 2004
* (E-Mail 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.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      16th Jul 2004
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
///


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Start background thread when a UI button is clicked, and Update UIbutton from background thread Curious Microsoft Dot NET 0 31st Mar 2010 10:01 PM
Returning custom IPrincipal from background thread to main thread delerium@blueyonder.co.uk Microsoft C# .NET 4 12th Jul 2007 09:52 AM
Thread safety of DataTable class - Filling on background thread OK? Alan Cobb Microsoft ADO .NET 9 1st Jul 2006 07:27 AM
Thread was being aborted thrown for background thread (win2003 ser =?Utf-8?B?Sm9oYW5uYQ==?= Microsoft ASP .NET 3 15th Oct 2004 02:35 PM
HowTo pass exception from background thread to main thread? Prozon Microsoft Dot NET 0 26th Mar 2004 03:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:47 PM.