0

I have a WPF and winform application both in C#. I invoke wpf app from winform app by using

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\wpfapp.exe";
startInfo.Arguments = data; //string result data from webservice;
Process.Start(startInfo);

This is ok and i am able to run the wpf ui from winform with the parameters that has been sent as arguments. But now i have a problem. now i want to update the message in the running wpf window.

Already the wpf window is run and showing the message. Later i want to send another message to that same wpf window. how we can achieve that ?

if (ProgramIsRunning(exepath))
{
    // here we need to add the code to send message to the same wpf window.
}
else
{
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = @"C:\wpfapp.exe";
    startInfo.Arguments = data; // string result data from webservice;
    Process.Start(startInfo);
}

Please help.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Jas
  • 1
  • 2
  • 1
    Look at this post: [What is the simplest method of inter-process communication between 2 C# processes?](https://stackoverflow.com/questions/528652/what-is-the-simplest-method-of-inter-process-communication-between-2-c-sharp-pro) maybe it can help you out. – Leon Apr 18 '19 at 15:03
  • I think msmq is arguably simpler than pipes. – Andy Apr 18 '19 at 18:55

1 Answers1

0

If you don't like pipes as described in this post, you can host simple REST server using Nancy in your WPF app and use something like HttpClient or RestSharp to communicate with it.

Example message listener application:

class Program {
    static void Main(string[] args) {
        var baseUri = new Uri("http://localhost:1234");
        var nancyHost = new NancyHost(baseUri);
        nancyHost.Start();

        Thread.Sleep(-1);
    }
}
public class SimpleRestModule : NancyModule {
    public SimpleRestModule() {
        Get["/Message"] = (args) => {
            return "Hello from server";
        };

        Post["/Message"] = (args) => {
            var receivedMessage = Request.Body.AsString();
            return "Message received";
        };
    }
}

Example message sender application:

class Program {
    static void Main(string[] args) {
        var httpClient = new HttpClient();

        var response = httpClient.PostAsync("http://localhost:1234/Message", new StringContent("Test message")).Result;
    }
}
Matas
  • 820
  • 9
  • 18