Search code examples
.netwcfnamed-pipesinterprocess

How do I obtain a handle on an object from another .NET process?


In C#, I know how to run a .NET executable from code and also find out if an instance of the executable is already running. What I would like to do is if an instance is already running, obtain an instance of the Foo object within the C# code of a different executable.

I have a windows application, (e.g..NET version of Outlook). A user can use the application as normal, but also running in the background is a process watching for an XML file from a third party system.

What I need is for the watcher process to start the .NET program if it is not running (or obtain a handle if it is), and then call the method CreateEmail on the object instance within the new/existing process.


Solution

  • Why don't you just added the FileSystemWatcher to the main application? That's if the background process is doing nothing else but monitoring for the XML files.

    If that's not feasible, you could use the NamedPipeServerStream and NamedPipeClientStream to send a "command" from the background process to the main application. When the main application receives this command, it will run the CreateEmail method.