I'm trying to do 2 things here:
Have only a single application instance running (I'm using the solution mentioned here for it..https://stackoverflow.com/a/522874/5159431) and
If another is attempted to be opened, the already open instance will show a balloon tip message or essentially any form control interaction (writing to a text box for example)
This is my modified Program.cs class:
static class Program
{
static readonly Mutex SingleInstanceMutex = new Mutex(false, "GUID here");
static TimerForm _mainForm;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
if (SingleInstanceMutex.WaitOne(TimeSpan.Zero, true))
{
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
_mainForm = new TimerForm();
Application.Run(_mainForm);
}
finally
{
SingleInstanceMutex.ReleaseMutex();
}
}
else
{
//Below message box works
MessageBox.Show("Already running");
//Below line throws null reference on second instance starting up
_mainForm.InvokeShowMinimizeBalloonTip();
}
}
}
What can I do call a method in the TimerForm
from the else
condition. You can assume InvokeShowMinimizeBalloonTip()
simply writes text to a text box on the form.