0

Its better if I describe this using code. I have the following interface:

public interface IMyInterface
{
    void DoSomething();
}

I have two Windows Form applications, called MyFirstApp and MySecondApp. Both applications implement the IMyInterface interface. MyFirstApp is calling MySecondApp like so:

var p = Process.Start("MySecondApp");

Everything if working as expected. Now what I want to do is, after MySecondApp launches, I'd like to be able to figure out how it was started (in this case, it was started by MyFirstApp) and if it was started my MyFirstApp, I'd like to be able to get a reference to the interface and call DoSomething() inside MyFirstApp. So the psuedo-code for MySecondApp will look like this:

if (this was started by MyFirstApp)
{
    IMyInterface firstApp = (IMyInterface)<handle to MyFirstApp>;
    firstApp.DoSomething();
}

My question is, how do I do this in C#?

4

1 回答 1

0

In this case, you want to have one application manage another application. You can do this by having the managed application host a simple WCF service which has operations like "ShutDown", "Configure", "GetStatistics", etc.

Depending on the scope of the management, you can use one of the Named Pipes bindings, which only work on a single machine, or one of the TCP bindings, which you might want to use within your Intranet, or one of the Http bindings, which can be used across the Internet.

All of these cases would use the exact same service code.

于 2013-05-22T20:45:38.703 回答