I know that this question could be a bit silly, but I am new to c#, and to coding in general. I recently made an app, and I want to restrict it to have only once instance of it running at a time, so that a user can't launch it multiple times. I found this answer by michalczerwinski on stackoverflow:
[STAThread]
static void Main()
{
bool result;
var mutex = new System.Threading.Mutex(true, "UniqueAppId", out result);
if (!result)
{
MessageBox.Show("Another instance is already running.");
return;
}
Application.Run(new Form1());
GC.KeepAlive(mutex); // mutex shouldn't be released - important line
}
Can anyone tell me where I am supposed to add this? I've tried adding it everywhere inside the Form1.cs, but it ain't working.