The scenario: We wrote a small program, let's call it MyLittleProggy.exe, that can be launched and it will continue to run, basically just idling.
MyLittleProggy.exe contains a public class Class1
Now we run AnotherProggy.exe
This is what we're trying to do:
- Check whether MyLittleProggy.exe is currently running, I assume by using System.Diagnostics.Process.GetProcessesByName - no need to explain this, but let's just say I find the Process so I know MyLittleProggy is running.
- Create a new instance of Class1 in this running process
Both applications will be written for .NET Framework 4.8
Is this possible and if so, how do I go about it? Do I work from the Process object I find, using its Modules, perhaps? Or do I need to use System.Reflection? Please note I am not looking for a fully worked out example, just a few pointers in the right direction as I am currently a bit lost in the weeds, and as a result I am also not sure how to ask the right questions so please be kind.... I'd be happy with short snippets of code in either C# or VB
Thank you
I'll give you two options, one that simply notifies
MyLittleProggyeach timeAnotherProggylaunches, and a second that sends data fromAnotherProggytoMyLittleProggy.For the "notification only" version, we'll use a named event. Here's
MyLittleProggy:And here's
AnotherProggy:This method uses an event that can be referenced by name by any program. The "heavy"
MyLittleProggydoes its heavy initialization once and then waits until something else triggers the event. The "light" application just triggers the event.Let's move on to the version that passes data. It uses a named pipe. Here's
MyLittleProggy:And here's
AnotherProggy:Conceptually this is very similar to the first example - you wait on an object to tell you when the lightweight application was launched. The difference here is that you are waiting on a pipe connection instead of a named event, and then you read from the pipe.
Hopefully this is enough to get you started.