private bool IsSingleInstance()
{
     foreach (Process process in Process.GetProcesses())
     {
          if (process.MainWindowTitle == this.Text)
               return false;
     }
     return true;
}
3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by ashishkumar008
0

this give error....
In foreach line (in process)
always mention namespace which is required and that place where code to be paste

1

Simple, yes... but not something I'd allow into production code. See these links for some discussion.

Here's an alternative... first, a method to try to create a mutex unique to the application:

private Mutex GetSingleInstanceMutex()
{
    bool createdNewMutex;

    Mutex mutex = new Mutex(false, @"Global\" + SomethingUnique, out createdNewMutex);

    if (!createdNewMutex)
    {
        mutex = null;
    }

    return mutex;
}

SomethingUnique should be something unique to the application, for example, the assembly GUID.

Here's how you'd use the method:

using (Mutex mutex = GetSingleInstanceMutex())
{
    if (mutex != null)
    {
        // This is the only running instance; go ahead and run the application.
    }
    else
    {
        // Another instance is running; notify user and quit.
    }
}
Comments
Very informative for a learner like me!
0

Request:-
i want to use flash file in webbrowser like other resources like picture
i do not want to use full path (c:\programfile\).
can u post full c# code
please

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.