Is there a way to raise an event in C# from an external application? In particular from Ruby? I have need to cause something to happen in C# from a rails application.
I assume that by "external application" you mean something that is outside of the process space of the C# code. Also, I assume that you're not referring to C# events - which aren't a concept that exists outside of the implementation domain of .NET - they aren't something that are accessible from outside of the code.
So the general answer to this question is is "yes it is possible" - but since you're essentially trying to send inter-process notifications you are going to need to use some kind of IPC mechanism.
.NET has a rich API for performing IPC, ranging from named pipes, to DCOM, to low-level networking protocols like TCP/IP. Which approach you use depends on the environment in which these process need to communicate (on a single machine, across machines on an intranet, over the internet, etc). It will also depend on the kind of information you're exchanging and how much effort you're willing to expend. For .NET 3.5 applications you can usually find an supported implementation using WCF as the unifying framework.
Obviously, all of this depends on your ability to modify the implementation (read source code) of the .NET application you're trying to raise an event within. If you can't do that, and there is no existing IPC mechanism in that code, you are likely stuck.
UPDATE: In response to your comment:
What would you recommend with priority of ease and time. Both apps are running on the same machine, and I am writing them both myself
I would consider using Named Pipes. Named pipes are originally a Unix concept - but they are available on Windows as well. They have a vary simple programming interface (they are similar to working with files), and don't require much to use in a single-machine scenario.
On the Ruby side (which I am less familiar with), here are some link that you may find useful:
On the .NET side, here are some relevant links to explore for more information:
An obvious solution would be to use a network message of sorts. Either a short-lived TCP/IP connection, or -- particularly if both apps are on the same host -- a simple UDP packet.
The C# application would accept connections (if TCP), read the event(s) from the socket and finally process them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With