Such a task is necessary so that when you start the application, 2 consoles appear, in the first one the data is output, in the second we enter commands to output the data in the first. How to implement it. Desirable example

  • one
    You can use WCF. Both examples and books are enough to cope with the task. - slippyk
  • one
    It seems that we will have to make two independent applications, communication between them - through, for example, SignalR. The main application hosts signalr, starts the slave application that clings to the main socket. - Pavel Dmitrenko
  • You need to spawn a child process to host additional console windows. If you really need it, here's an example in C ++ . - Lunar Whisper
  • One app or two? - Qwertiy

1 answer 1

This is easily implemented by means of RabbitMQ + Masstransit .

1) Create a class that represents the message that applications will exchange.

public class Message { public string Text { get; set; } } 

2) Create an application that will send messages. Therefore, first install MassTransit.RabbitMQ

 Install-Package MassTransit.RabbitMQ -Version 3.5.7 

 static void Main(string[] args) { Console.Title = "Publisher"; var bus = Bus.Factory.CreateUsingRabbitMq(x => x.Host(new Uri("rabbitmq://localhost/"), h => { })); bus.Start(); var text = ""; while (text != "выход") { Console.Write("Введите сообщение: "); text = Console.ReadLine(); var message = new Message() { Text = text }; bus.Publish(message); } bus.Stop(); } 

3) Create an application that will receive messages. Therefore, we also install MassTransit.RabbitMQ

 Install-Package MassTransit.RabbitMQ -Version 3.5.7 

  static void Main(string[] args) { Console.Title = "Subscriber"; var bus = Bus.Factory.CreateUsingRabbitMq(x => { var host = x.Host(new Uri("rabbitmq://localhost/"), h => { }); x.ReceiveEndpoint(host, "SubscriberQueue", e => e.Handler<Message>(a => { Console.WriteLine(a.Message.Text); return Task.CompletedTask; })); }); bus.Start(); Console.ReadKey(); bus.Stop(); } 
  • 2
    Cons for what, would explain though. The solution does not work or does not allow to implement what the author of the question wants? - sp7
  • @ sp7 I’ve given you a favor, but about the solution, it’s too far somewhere in the jungle, I wanted to use the standard libraries c # - polsok
  • @polsok, if you are satisfied with two different applications, then you can try implementing on NamedPipe - Andrey NOP
  • 2
    @polsok, thanks for the feedback. I gave this example, only as one of the possible solutions to this problem. It is simple, easy to implement, plus the use of RabbitMQ + Masstransit provides a bunch of different buns. It may not be useful in your particular situation, but knowing about it will be useful. - sp7