Basically I have C# winforms application with single instance openable on a system using below lines of code.
internal static class Program
{
private static readonly Mutex _mutex = new Mutex(true, "f70bd07d-e882-469c-8bcd-d2a267ab0602");
[STAThread]
private static void Main()
{
if (_mutex.WaitOne(TimeSpan.FromSeconds(3), true))
{
Application.Run(MyForm);
_mutex.ReleaseMutex();
}
else
{
MessageBox.Show("Sorry, another user is currently using.",
"Information",
MessageBoxButtons.OK,
MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1);
}
}
}
So, in above case I want to show a user details who have opened my application initially to the second user who attempt to open it.
I have tried to add some static class property, but it is not storing value from first user.
Expected results should be
internal static class Program
{
private static readonly Mutex _mutex = new Mutex(true, "f70bd07d-e882-469c-8bcd-d2a267ab0602");
[STAThread]
private static void Main()
{
if (_mutex.WaitOne(TimeSpan.FromSeconds(3), true))
{
Application.Run(MyForm);
_mutex.ReleaseMutex();
}
else
{
MessageBox.Show("Sorry, another user " + userName + " is currently using.",
"Information",
MessageBoxButtons.OK,
MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1);
}
}
}