|
Yes, this is possible. You have to use System.Threading.Mutex. This is a system wide handle for an application. A mutex has a system wide mutex name i.e. "MYAPPLICATION". You can check for the mutex and if it exists, you know that your application is already running and you can react accordingly. Here is an example from a book:
using System.Threading;
class Program
{
static void Main(string[] args)
{
Mutex oneMutex = null;
const string MutexName = "RUNMEONLYONCE";
try // Try and open the Mutex
{
oneMutex = Mutex.OpenExisting(MutexName);
}
catch (WaitHandleCannotBeOpenedException)
{
// Cannot open the mutex because it doesn't exist
}
// Create it if it doesn't exist
if (oneMutex == null)
{
oneMutex = new Mutex(true, MutexName);
}
else
{
// Close the mutex and exit the application
// because we can only have one instance
oneMutex.Close();
return;
}
Console.WriteLine("Our Application");
Console.Read();
}
}
Let me know if this helped you!
Cheers
Peter
|
|
Expert:
|
PeterNZ
|
|
Date:
|
Jul 03, 2007
|
|
Time:
|
15:25
|
|
|
|
Votes: Good (0) | Bad (0) Login to rate this answer
|
|
|
Thanks, Peter. this is perfect!
|
|
Expert:
|
theDude
|
|
Date:
|
Jul 05, 2007
|
|
Time:
|
03:01
|
|
|
|
Votes: Good (0) | Bad (0) Login to rate this answer
|
|
|
For VB.NET take Project Properties --> Enable Application Framework --> Windows Application Framework Properties --> Check in Make Single Instance Application
|
|
Expert:
|
Prajith
|
|
Date:
|
Jul 24, 2007
|
|
Time:
|
13:26
|
|
|
|
Votes: Good (0) | Bad (0) Login to rate this answer
|
|
|
|
|
|
|
This question has been answered, and points have been rewarded to the following experts:
You're welcome however to comment or give additional information or if you wish, you have the ability to write an Answer Summary for this question by clicking on the "Answer Summaries" Tab.
|
|