开发者

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.


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

Check out the following sample: About .NET Remoting: Three concepts Compared and Simplified


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.


Use the System.Diagnostics.Process class.

To run, you can Process.Start("string path"); and also list current running processes to perform the check.


Well, you can use:

Process.GetProcessesByName(<process Name here>);

which returns Process[].

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜