标签云

微信群

扫码加入我们

WeChat QR Code

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.


Welcome to SO :o)

2019年07月20日30分25秒

Do you want to obtain a handle to the already running foo.exe process or do you want to get an instance of an object used by foo.exe? Could you clarify what you want to do with the existing process?

2019年07月21日30分25秒

Ideally I would like a handle on the object passed to Application.Run...

2019年07月20日30分25秒

What kind of object is that? Would you simply like to execute some action in the already running process? Read some data? It's difficult to help without knowing further details. Could you describe what your applications should do?

2019年07月21日30分25秒

I have a windows application, for this example let's say it's a .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 Outlook 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.

2019年07月20日30分25秒

Or use WCF over a named pipe channel -- saves writing your own protocol down at the byte stream level.

2019年07月21日30分25秒

as of .Net 3.5, .Net now supports named pipes.No writing your own protocol.The NamedPipeServerStream and NamedPipeClientStream are very easy to use for IPC.I did a blog post about it a few weeks ago.eclipsed4utoo.com/blog/…

2019年07月20日30分25秒

Consider the main application as signed and sealed.The watcher is a customer specific tool so I don't want it integrated into the main source code.

2019年07月21日30分25秒

After some quick tests, it seems that using WCF over a named pipe channel gives me exactly what I need. Thanks to Eclipsed4utoo and itowlson for the suggestions!

2019年07月20日30分25秒

Excellent idea.Thank you!

2019年07月20日30分25秒

Remoting is deprecated because it allows processes to fiddle around with each other's internals.This is brittle and can lead to nasty surprises (as you can't control what the external process does to your objects).A better way would be for the target process to host a WCF service: because this is a message-based interface, it insulates the calling process from the implementation of the target process (allowing change) and allows the target process to control what is done to its objects and when (preventing surprises).

2019年07月20日30分25秒

WCF sounds like a good option - I'll look into it.

2019年07月20日30分25秒

Thanks for the reply, but as I had said:"I know how to run a .NET executable (foo.exe) from code and also find out if an instance of the executable is already running"

2019年07月20日30分25秒

Misread, thought it was "need to know", apologies.

2019年07月21日30分25秒

Your title says "How to start a .NET process...", so perhaps that should be removed.

2019年07月21日30分25秒

Done.Hopefully it's a bit clearer.

2019年07月20日30分25秒

Thanks for the reply, but as I had said: "I know how to run a .NET executable (foo.exe) from code and also find out if an instance of the executable is already running"

2019年07月20日30分25秒