views:

276

answers:

1

i have used following code to repeat a process creation/close iteratively

dim vProcessInfo as new ProcessInfo
For i= 1 to 100
dim p as new Process
vProcessInfo.Arguments = "some"+i.toString()
p.StartInfo = vProcessInfo
p.Start()
p.WaitForExit()
p.Close()
Next i

the above code worked for me successfully. but it takes too much time for process creation and dispose. i had to change process argument dynamically in the iteration. is there any way to change the process argument dynamically. or is there any better method to reduce time. pls help me

+2  A: 

"Is there any way to change the process argument dynamically" - do you mean you want to start one process, and change its command line arguments after it's started? No, you can't do that - but you could communicate with it in other ways, for example:

  • Using standard input/output (e.g. write lines of text to its standard input)
  • Using files (e.g. you write to a file, it monitors the directory, picks up the file and processes it)
  • Using named pipes or sockets

Creating a process is a relatively slow operation. You can't easily speed that up - but if you can change your process in some way like the above, and just launch it once, that should make it a lot faster.

Jon Skeet
thanks for ur answer but the exe is not created by me, so it doesn't take files input.
JKS
Well if the application is forcing you to create a new process each time, I don't see that you have much option. You're sure you can't pass it multiple options in one go?
Jon Skeet