Пример #1
0
        static void Main(string[] args)
        {
            int          cnt          = 0;
            SharedMemory sharedMemory = new SharedMemory();

            while (!Console.KeyAvailable)
            {
                var read = sharedMemory.ReadStringM2D();
                if (read.Length > 0)
                {
                    var baseObject = JsonSerializer.Deserialize <Communication.Base>(read);
                    if (baseObject.type == "Hello")
                    {
                        var hello = JsonSerializer.Deserialize <Communication.Hello>(baseObject.json);
                        Console.WriteLine("[" + baseObject.type + "]" + hello.msg);
                    }
                }

                sharedMemory.WriteStringD2M(JsonSerializer.Serialize(new Communication.Base
                {
                    type = "Hello",
                    json = JsonSerializer.Serialize(new Communication.Hello
                    {
                        msg = "Hello from C# mock"
                    })
                }));
                cnt++;
                Thread.Sleep(500);
            }
        }