I am trying to send parameters to an application which is already in the processor. I am using Mutex to find if the application is running or not already. I need to send any command line parameter and that text is added to the listbox. But the parameter is going in but the values are not getting added to the listbox. Application's name is "MYAPPLICATION" and the function which adds the value to listbox is parameters()
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 Frm1 = new Form1();
bool createdNew = true;
using (Mutex mutex = new Mutex(true, "MYAPPLICATION", out createdNew)) //Finding if application is running or not
{
if (createdNew)
{
//foreach (string abc in Environment.GetCommandLineArgs())
//{
// MessageBox.Show(abc);
//}
Application.Run(Frm1);
}
else
{
Process current = Process.GetCurrentProcess();
foreach (Process process in Process.GetProcessesByName(current.ProcessName))
{
if (process.Id != current.Id)
{
SetForegroundWindow(process.MainWindowHandle);
Frm1.parameters(Environment.GetCommandLineArgs());
break;
}
}
}
}
}