Is anonymous channel the right way?

I have an application consisting of two exes. Name them MyApp.exe

and MyAppStarter.exe

. The reason I have MyAppStarter.exe

is that she can check the net first if there is a new version MyApp.exe

available so she can copy it before launching it, but it's somewhat near that point.

What I would like to achieve is to register a custom url protocol handler for MyAppStarter.exe

so that I can pass some startup conditions to MyApp.exe

. For example, if a user clicks on a link in an email message at myapp: // userid = 123 , they should launch the app and immediately view the user with userid 123. Or, if the link myapp: // accid = 456 , it should immediately view the account entry with accid 456. It is I know how to do this by registering a custom url protocol handler for MyAppStarter.exe

and then shell MyApp.exe

with specific arguments. So far so good.

Now the problem is that if MyApp.exe

already started, I want to be able to MyAppStarter.exe

recognize this (this I can do) and give it focus (this can also be done) and instruct it to show the user or account or whatever with the specified id (that's where I got stuck).

I have looked at the MSDN documentation on How to Use Anonymous Pipes for Local Interprocess Communication . This seems straightforward enough, but there are two things I don't understand about:

  • How do I pass the pipe handle between the two so that the pipe can be installed first? Remember, it MyApp.exe

    may already be executing at the point where it is executing MyAppStarter.exe

    .

  • In my scenario, I would assume it MyAppStarter.exe

    will be the server and MyApp.exe

    will be the client. This means that I need to set up a timer in MyApp.exe

    , which so often checks the channel for instructions from MyAppStarter.exe

    . I am not mad at this idea. It's just that the requirement is a minor part of the operation MyApp.exe

    , so for it to start the timer every second or, as often as it may seem, I would say less elegant. I wish I could just define a function in MayApp.exe

    called void PerformInstruction(string instruction)

    that can be called fromMyAppStarter.exe

+3


source to share


2 answers


When you use pipe / sockets, you will have a stream that will handle requests from MyStarterApp.exe all the time. Your client will wait for the ReadLine to complete, and you will keep reading until you receive a signal from the FIN server, or the pipe is closed on the other side, in which case you will return a NULL method. Be sure to familiarize yourself with the behavior of the StreamReader.



In your MyApp.exe file, you need this thread to communicate with the UI / Consumer and select the appropriate user.

+1


source


.NET Remoting makes this pretty easy. This technology is considered obsolete by many, but it is still fully functional and ingrained in .NET. I doubt it will disappear soon. For local machine IPC or AppDomain "IPC" I find Remoting a good solution.

The class IpcChannel

does exactly what you want. You can see from the tutorial how easy it is to do this. The pipe handles do not need to be exchanged because the end points are indicated.



Make the mistake of writing your own named pipe binary protocol. Feel free to choose something other than Remoting.

Make MyApp

server and MyAppStarter

client. If MyApp

not, the connection should be up immediately (no timeout required).

+1


source







All Articles