My VB.NET WinForms program (parent) calls another VB.NET Console pro开发者_StackOverflow中文版gram (child) with Process.Start()
. The child application runs quickly and I would like a status message returned to the parent. How can I send a string from the child to parent?
Is there some built-in way because of the parent-child relationship or must I use some other interface like sockets?
Just to add some code to my other comment, imagine the following simple child program:
Module Module1
Sub Main()
Console.WriteLine("This is a test")
End Sub
End Module
And here's the parent:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim P As New Process()
P.StartInfo.FileName = "Child.exe"
P.StartInfo.RedirectStandardOutput = True
P.StartInfo.UseShellExecute = False
P.Start()
Dim T = P.StandardOutput.ReadToEnd()
'Do something with T
End Sub
End Class
You can have your calling application send command line arguments via Proccess.Start(), which your called app then uses.
Depending on your requirements / architecutre, this is either a good, simple design; or a terrible idea.
I'll assume the former; but if it is the latter, I highly recommend using the WCF for this. Direct socket calls have long been the way of the dodo, save for high volume/performance apps like video games. And with the WCF you can have a client sending it's server app data in very few lines of code.
What are your requirements here? Will the messages be sent frequently or just on the start? How often does that happen?
精彩评论