Exemplo n.º 1
0
 public void Start()
 {
     Task.Run(() =>
     {
         var process = StartRunner("Runner", new string[] { @"D:\Temp\AppHost\" }, new string[0]);
         using (var connection = new TwoWayNamedPipeConnection <string>(Name, null, null))
         {
             connection.Connect();
             connection.StartRecieving(x => Console.WriteLine(x));
             while (!cancellation.Token.IsCancellationRequested)
             {
                 Task.Delay(500);
             }
             connection.Dispose();
         }
     });
 }
        public void X()
        {
            var allText      = "";
            var recieveCount = 0;
            var message      = "";

            Task.Run(() =>
            {
                using (var connection1 = new TwoWayNamedPipeConnection <TestMessage>("Test1", new NamedPipesJsonReader <TestMessage>(), new NamedPipeJsonWriter <TestMessage>()))
                {
                    connection1.Connect();
                    connection1.StartRecieving(x => { recieveCount += 1; message += x.Name; allText += $"connection1Recieved:'{x.Number}-{x.Name}{Environment.NewLine}'"; });
                    while (recieveCount < 50)
                    {
                        connection1.Send(new TestMessage {
                            Name = "SendFrom1", Number = recieveCount
                        });
                    }
                }
            });

            Task.Run(() =>
            {
                using (var connection2 = new TwoWayNamedPipeConnection <TestMessage>("Test1", new NamedPipesJsonReader <TestMessage>(), new NamedPipeJsonWriter <TestMessage>()))
                {
                    connection2.Connect();
                    connection2.StartRecieving(x => { recieveCount += 1; message += x.Name; allText += $"connection2Recieved:'{x.Number}-{x.Name}{Environment.NewLine}'"; });
                    while (recieveCount < 50)
                    {
                        connection2.Send(new TestMessage {
                            Name = "SendFrom2", Number = recieveCount
                        });
                    }
                }
            });

            while (recieveCount < 50)
            {
                Thread.Sleep(10);
            }
            var b      = message;
            var result = allText;
        }
Exemplo n.º 3
0
        public void Test()
        {
            var allText      = "";
            var recieveCount = 0;
            var message      = "";

            Task.Run(() =>
            {
                using (var connection1 = new TwoWayNamedPipeConnection <string>("Test2", new NampedPipesLineReader(), new NamedPipesLineWriter()))
                {
                    connection1.Connect();
                    connection1.StartRecieving(x => { recieveCount += 1; message = x; allText += $"connection1Recieved:'{x}'"; });
                    while (recieveCount < 5)
                    {
                        connection1.Send("connection1");
                    }
                }
            });

            Task.Run(() =>
            {
                using (var connection2 = new TwoWayNamedPipeConnection <string>("Test2", new NampedPipesLineReader(), new NamedPipesLineWriter()))
                {
                    connection2.Connect();
                    connection2.StartRecieving(x => { recieveCount += 1; message = x; allText += $"connection2Recieved:'{x}'"; });
                    while (recieveCount < 5)
                    {
                        connection2.Send("connection2");
                    }
                }
            });

            while (recieveCount < 5)
            {
                Thread.Sleep(10);
            }
            var b      = message;
            var result = allText;
        }
Exemplo n.º 4
0
        private static void Main(string[] args)
        {
            if (args.Any(x => x.ToLower() == "--debug"))
            {
                Debugger.Launch();
                Debugger.Break();
            }
            var id     = args[0];
            var folder = args[1];

            Console.WriteLine(id);
            Console.WriteLine(folder);

            using (var connection = new TwoWayNamedPipeConnection <string>("", null, null))
            {
                connection.Connect();
                while (true)
                {
                    Console.WriteLine($"im alive {DateTime.UtcNow} 2");
                    Thread.Sleep(1000);
                    connection.Send(DateTime.UtcNow.ToString());
                }
            }
        }