views:

55

answers:

0

hi.

I used the following code to verify the single instance of application. On Win XP X86 it is working fine, but on X64 after 3 to 4 minutes System generates StackOverflowException and causes the application to hang. after removing this check application is working fine..

Please tell me what should be the reason.

code is

static void Main()
   {
      bool instanceCountOne = false;

      using (Mutex mtex = new Mutex(true, "AppName", out instanceCountOne))
      {
         if (instanceCountOne)
         {
#if (DEBUG)
            RunInDebugMode();
#else
            RunInReleaseMode();
#endif
            mtex.ReleaseMutex();
         }
         else
         {
            MessageBox.Show(
               "An application instance is already running",
               "App Name",
               MessageBoxButtons.OK,
               MessageBoxIcon.Information);
         }
      }
  }

it crashes when single instance of application is running.