Calling a method from a different process C#

1.5k views Asked by At

I want call a method accepting a string as parameter on a console application from a completely different application. Purpose of the call is simply write a line to the console window from a different application for posting some debug lines. What could be the best way to achieve this? (I have control of both application sources)

1

There are 1 answers

1
Tomáš Hübelbauer On

You could use anonymous pipes (on local machine) or named pipes (if you require the processes to communicate over network as well). Pipes are very common way for processes to communicate, other solutions include memory mapped file where the processes exchange messages or, and I very much discourage you to do this, a directory where messages are exchanged in form of files being created and their creation observed using FileSystemWatcher.

You can see an example of names pipes in action on How to: Use Named Pipes for Network Interprocess Communication on MSDN. The example demonstrates two processes where one of them uses NamedPipeServerStream and the consuming processes use NamedPipeClientStreams to be able to intercept the incoming messages from the server application.

Here's an example of the same thing using anonymous pipes, if you don't require the processes to work over the network.