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);
}
}
Thoughts?
What I have tried:
Memory mapped file, EventWaitHandle, Mutex