How can I send a “Message” to another process in .Net without using SendMessage?

I have several applications running on the same machine. One of them does the work and writes logs to the disk about what he did (I will call this WorkerApp), and the other, which summarizes information about the support of the WorkerApp status along with some details (I will call this dashboard).

From the dashboard, I want to instruct WorkerApp to take an action (say, “remote ping services”), and I would like WorkerApp to send a “pong” response to the Dashboard when it receives it.

I saw examples of using SendMessage , but it seems pretty archaic (now there is nothing more standard in 2016 for between communication processes?).

I have very little experience with Akka.Net , but Remoting seems like a good approach, although setting this up seems a bit overpriced for what I would like to do.

What is the easiest way to exchange information between two processes in .NET? And are there some examples of this while working on a local machine?

+5
source share
3 answers

I put together an Akka.Net example for this. Here is how it looks.

DashBoard (sends messages)

using System; using Akka.Actor; using Akka.Configuration; namespace DashBoard { class Program { static void Main(string[] args) { var config = ConfigurationFactory.ParseString(@" akka { actor { provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote"" } remote { helios.tcp { transport-class = ""Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote"" applied-adapters = [] transport-protocol = tcp port = 0 hostname = localhost } } } "); using (var system = ActorSystem.Create("Dashboard", config)) { var server = system.ActorSelection("akka.tcp:// WorkerApp@localhost :8081/user/WorkerAppActor"); while (true) { var input = Console.ReadLine(); server.Tell(input); } } } } } 

WorkerApp (accepts messages)

 using System; using Akka.Actor; using Akka.Configuration; namespace WorkerApp { class Program { static void Main(string[] args) { var config = ConfigurationFactory.ParseString(@" akka { actor { provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote"" } remote { helios.tcp { transport-class = ""Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote"" applied-adapters = [] transport-protocol = tcp port = 8081 hostname = localhost } } } "); using (var system = ActorSystem.Create("WorkerApp", config)) { system.ActorOf<WorkerAppActor>("WorkerAppActor"); Console.ReadLine(); } } } class WorkerAppActor : TypedActor, IHandle<string> { public void Handle(string message) { Console.WriteLine($"{DateTime.Now}: {message}"); } } } 
+2
source

Take a look at .Net remoting. This is a bit more modern than SendMessage, but not so much. It is pretty easy to use, though. I think the official way to do this these days probably uses WCF, but I'm sure it is exactly the same under the hood.

.Net remoting supports various channels (Http, TCP), but in your case, I suggest removing IPC. It sits on top of named pipes.

Probably the easiest way is if you are google (.Net remoting), but the general idea is to define a class in your "server" application derived from MarshalByRefObject. Once you have done this, register it using the remote infrastructure using RemotingConfiguration.RegisterWellKnownServiceType.

Then, your client application can instantiate the class using Activator.CreateObject, and then you will be fine.

One thing you need to know about: it looks like you will need a callback mechanism, so your dashboard will not be blocked waiting for your WorkerApp. This is supported in removing the .Net network, but you need to create two channels - one for outgoing calls (from Dashboard to WorkerApp), and then another for incoming callbacks.

Another suggestion: your working class (the one derived from MarshalByRefObject) will be easier to handle if you also discover the interface. Put this interface in the DLL, accessible for both applications, and life will be easier.

+1
source

One suggestion might be to use a database or other persistent storage to create a type of “queue” onto which the toolbar can paste tasks. It can also save statuses about tasks that can be updated by the workflow. Although this can be considered "redundant," it brings many benefits, such as auditing, historical reporting, and server redundancy / power off. This will probably also simplify the application in the future.

+1
source

All Articles