I can pass arguments into my application on startup, which works great! I can also stop multiple instances of the application from running which is great. However I'm trying to pass an argument into the application, but if the app is already running then run a method on the existing winform, instead of trying to open a new instance. I've tried using application.openforms and it doesnt appear to work for me.
I've tried using code similar to this:
if (System.Windows.Forms.Application.OpenForms["MainMenu"] != null)
{
(System.Windows.Forms.Application.OpenForms["MainMenu"] as Form1).Output();
}
Program.cs
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1)
{
MessageBox.Show("BorisCRM is already running. Only one instance of this application is allowed");
}
else
{
if (args.Length > 0)
Application.Run(new Forms.MainMenu(args[0]));
else
Application.Run(new Forms.MainMenu("NoArg"));
}
}
MainMenu Form:
if (s != "NoArg")
{
NewForm frm = new NewForm(getclient);
frm.MdiParent = this;
frm.Show();
}
THIS WORKS.... open application - opens menu form, where i can choose menu items that open forms using the menu as its mdiparent.
THIS WORKS.... open application with argument - opens the menu form, and automatically opens another form using the menu as the parent mdi.
THIS DOESNT WORK... open application with argument (when the application is already running) - existing menu form automatically opens another form using the menu as the parent mdi.