Last active
October 24, 2019 20:15
-
-
Save Legends/7b40f6359e3c20d91cdfdeaea3b83984 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Server.exe: | |
| var s = new Semaphore(0, 1, Constants.SemaphoreName); // public static readonly string SemaphoreName = @"Global\semName"; | |
| var p = Process.Start(@"C:\Users\...\Debug\IpcChannelClient.exe"); | |
| p.EnableRaisingEvents = true; | |
| p.Exited += P_Exited; | |
| //p.WaitForExit(); | |
| Console.WriteLine("Entering waitone at: " + DateTime.Now.ToLocalTime()); | |
| // Thread waits here until the sempahore is signaled (freed) from client process called above | |
| // we use semaphore here for demo purposes, but for waiting we would normally use p.WaitForExit() | |
| s.WaitOne(); // <-- thread waits here | |
| // Client.exe | |
| // ..do work here... | |
| if (Semaphore.TryOpenExisting(Constants.SemaphoreName, out Semaphore s)) | |
| { | |
| s.Release(); //Signal it here, so that server.exe can continue | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment