I need to call from my code for some other program .
And I nee开发者_JAVA技巧d to wait till it finishes (synchronous call).
How I can do so ?
Thanks, a lot.
Try using the WaitForExit method.
Process p = new Process();
// Redirect the error stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = "OtherProgram.exe";
p.StartInfo.Arguments = "My Arguments";
p.Start();
// Wait for the child process to exit.
p.WaitForExit();
Unless you explicitly make an asynchronous the call will be synchronous (and therefore block the current thread). The details of doing these depend on the selected application to application communication mechanism you are using.
This could be:
- TCP/IP
- HTTP
- WCF
- SharedMemory
- Named Pipes
and many more. All of these allow you to wait for a response.
But the specifics are very different (as is when you would use each), so without more details of the type of communications you are trying to achieve one cannot be more specific.
精彩评论