Skip to content

Instantly share code, notes, and snippets.

@Legends
Last active October 24, 2019 20:15
Show Gist options
  • Select an option

  • Save Legends/7b40f6359e3c20d91cdfdeaea3b83984 to your computer and use it in GitHub Desktop.

Select an option

Save Legends/7b40f6359e3c20d91cdfdeaea3b83984 to your computer and use it in GitHub Desktop.
// 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