Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
C#
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
Posted
Updated 28-May-19 6:08am

1 solution

Quote:
What are the down sides of using MemoryMappedFile?


c# - Disadvantages of using memory mapped files - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900