shell和app之间的通信(winform) [英] Communication between shell and app (winform)

查看:119
本文介绍了shell和app之间的通信(winform)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个winform shell(shell),它可以使用Process.Start(startInfo)在其中(在面板上)运行其他winform应用程序(App1);

注意:使用引用App1.exe不是一个选项。



Shell希望收听App1的事件和消息,最好的方法是什么?



使用MemoryMappedFile有什么缺点?

I want to create a winform shell (shell) which could run other winform application (App1) inside it (on a panel) using Process.Start(startInfo);
Note: Using reference to App1.exe is not an option.

Shell want to listen to the events n messages of App1, what is the best way to accomplish it?

What are the down sides of using MemoryMappedFile?

Shell Code-
 using (MemoryMappedFile mmf = MemoryMappedFile.CreateOrOpen("AppWinShell", 1024))
            using (MemoryMappedViewStream view = mmf.CreateViewStream())
            {
                BinaryReader reader = new BinaryReader(view);
                EventWaitHandle signal = new EventWaitHandle(false, EventResetMode.AutoReset, "WinShellEvent");
                Mutex mutex = new Mutex(false, "WinShellMutex");

                while (true)
                {
                    signal.WaitOne();
                    mutex.WaitOne();
                    reader.BaseStream.Position = 0;
                    string message = reader.ReadString();
                    WriteTextSafe(message);
                    mutex.ReleaseMutex();
                }
            }
App1 code -

        private void SendMessage()
        {
            using (MemoryMappedFile mmf = MemoryMappedFile.CreateOrOpen("AppWinShell", 1024))
            using (MemoryMappedViewStream view = mmf.CreateViewStream())
            {
                BinaryWriter writer = new BinaryWriter(view);
                EventWaitHandle signal = new EventWaitHandle(false, EventResetMode.AutoReset, "WinShellEvent");
                Mutex mutex = new Mutex(false, "WinShellMutex");

                mutex.WaitOne();
                writer.BaseStream.Position = 0;
                System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();
                writer.Write(PID + "^" + txtMessage.Text);
                signal.Set();
                mutex.ReleaseMutex();

                Thread.Sleep(10);
            }
        }







想法?



我尝试了什么:



内存映射文件,EventWaitHandle,Mutex




Thoughts?

What I have tried:

Memory mapped file, EventWaitHandle, Mutex

推荐答案

引用:

使用MemoryMappedFile有什么缺点?

What are the down sides of using MemoryMappedFile?





c# - 使用内存映射文件的缺点 - 堆栈溢出 [ ^ ]


这篇关于shell和app之间的通信(winform)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆