I would like to pass command line arguments of a new instance of my application to one already running (if one exists). So far, I have tried the following:
Program.cs
string[] Arguments = Environment.GetCommandLineArgs();
int iCurrentProcessID = -1;
using (Mutex mutex = new Mutex(true, Arguments[1], out createdNew)) //Finding if application is running or not
{
Process current = Process.GetCurrentProcess();
iCurrentProcessID = current.Id;
if (createdNew)
{
Application.Run(Frm1);
}
else
{
// Process current = Process.GetCurrentProcess();
Process CurrentAutomation = Process.GetProcessById(iCurrentProcessID);
string[] strArguments = Environment.GetCommandLineArgs();
if (!string.IsNullOrWhiteSpace(strArguments[2]))
{
frmMain.strEndtime = strArguments[2];
}
Form.cs
public partial class frmMain : Form
{
public static string strEndtime;
//...
}
Values are set correctly in the second instance, but are not set in the first (started earlier) one. How do I pass those values to the other instance of my application?