0

i want to make sure that only one instance of application run...

i added the mutex check but it causes problem in 64 bit system. the second way is to search process table.. This check can be easily defeated by renaming application. please tell me how to make sure that only one instance of application run.

following code is used for mutex

bool createdNew = true;
using (Mutex mutex = new Mutex(true, "MyApplicationName", out createdNew))
{
if (createdNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}

the problem with this on XP 64 bit after 2 or 3 minutes it generates StackOverflowExcpetion and causes my application to crash.. i thoroughly tested and came to result that use of mutex is causing this problem

Mohsan
  • 2,483
  • 6
  • 47
  • 62
  • 1
    What problems are caused by the Mutex? – Femaref Jun 07 '10 at 11:20
  • Run your code in a debugger and look at the call stack. – SLaks Jun 07 '10 at 11:24
  • Possible duplicate of [What is the correct way to create a single-instance application?](http://stackoverflow.com/questions/19147/what-is-the-correct-way-to-create-a-single-instance-application) – user Mar 07 '16 at 07:33

2 Answers2

1

Mutexes should work fine on 64-bit systems.
Please show us your code.

Alternatively, you could use the WindowsFormsApplicationBase class in Microsoft.VisualBasic.dll (which is usable from C#), which already implements this for you.

To use it, set the IsSingleInstance property to true, set the MainForm property to your form, then call Run.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
1

The use of mutexes is the right way, searching process table the wrong one. You must have some errors in your code if mutexes isn't working for you. Could you post the valid code parts?

codymanix
  • 28,510
  • 21
  • 92
  • 151