Send a String From Child Application to Parent

不打扰是莪最后的温柔 提交于 2020-01-15 09:44:21

问题


My VB.NET WinForms program (parent) calls another VB.NET Console program (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?


回答1:


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



回答2:


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?



来源:https://stackoverflow.com/questions/2638686/send-a-string-from-child-application-to-parent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!