shell和app之间的通信(winform) [英] Communication between shell and 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?
这篇关于shell和app之间的通信(winform)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!