How to get an object descriptor from another .NET process?

In C #, I know how to run a .NET executable from code, and also find out if an instance of an executable is running. I would like to do if an instance is already running, get an instance of the object Fooin the C # code of another executable file.

I have a Windows application (e.g. .NET version in Outlook). The user can use the application as usual, but also works in the background - this is a process that watches an XML file from a third-party system.

I need the observer process to run the .NET program if it is not running (or get the handle, if any), and then call the CreateEmailobject instance method in a new / existing process.

+3
source share
4 answers

Why didn't you just add FileSystemWatcher to the main application? This is if the background process does nothing but monitor the XML files.

If this is not possible, you can use NamedPipeServerStreamit NamedPipeClientStreamto send a “command” from the background process to the main application. When the main application receives this command, it will start the method CreateEmail.

+1
source

You can activate an object in an already running application using .NET Remoting.

See the following example: About .NET Remoting: Three Concepts Comparable and Simplified

+2
source

System.Diagnostics.Process.

Process.Start("string path");, .

+1

, :

Process.GetProcessesByName(<process Name here>);

Process [].

Check the static methods of the Process class, they are very intuitive and useful.

0
source

Source: https://habr.com/ru/post/1720121/


All Articles