title: Use Mutex(??) to check allow for only 2 living application instances
body: <p>I understand that <a href="https://stackoverflow.com/questions/229565/what-is-a-good-pattern-for-using-a-global-mutex-in-c">Mutex can be used</a> to allow only one instance of my app starting on a single machine. This means that no matter how many desktops are used by an arbitrary number of users, there can be at most one instance of the program running.</p>
  
  <p>Now, instead of only allowing one instance, I want to allow for at most <em>two</em>, nothing more. How to do it? I tried code such as this:</p>
  
  <pre><code>    public static bool MutexChecking()
      {
  
              bool createNew1;
              // one set of GUID
              new Mutex(false, "54A8F2C1-6C11-4ED4-8A62-AD7C1D9F7970", out createNew1);
  
  
  
              if (createNew1)
                  return true;
              bool createNew2;
               //another set
                new Mutex(false, "5E1C76D0-9897-412B-BD56-64A872F8FDE3", out createNew2);
  
              return createNew2;
  
      }
  </code></pre>
  
  <p>The above code works... sort of. It works in all the cases I have tested except this one:</p>
  
  <ol>
  <li>Open the program( let's call it <code>p1</code>)</li>
  <li>Open the program again ( let's call it <code>p2</code>)</li>
  <li>Close <code>p1</code>.</li>
  <li>Open the program a third time ( <code>p3</code>)</li>
  <li>Expectation: during <code>p3</code> , the above method should return a true ( because <code>createNew1</code> should be <code>true</code>), but it returns a false ( because   <code>createNew1</code> returns <code>false</code>). </li>
  </ol>
  
  <p>Why is this so? Any idea how to fix this? </p>