I have created 2 application: AppA.exe and AppB.exe.
App A is running on windows startup by adding a key in
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run.
My AppA.exe is simple like below:
if (!IsLatestVersion())
{
if(MessageBox.Show("There is a new version. Do you want to update?", "Confirmation", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
{
Process.Start(AppB.exe)
}
}
But when I click Yes on messagebox dialog. Nothing happened.
I try to run directly by double click to AppA.exe, then AppB.exe runs normally. I think maybe when windows onstartup start my AppA.exe, it blocked all thread so I cannot run AppB.exe through AppA.exe.
Is there any solution? Thanks.
There is an example.
On WindowsFormsApp1.exe:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//set registry so App1 can run on windows startup
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
rkApp.SetValue("App1", Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "WindowsFormsApp1.exe"));
//Confirmation open App2
if (MessageBox.Show("Do you want to run App2?", "Confirmation", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
{
Process.Start("WindowsFormsApp2.exe");
}
Close();
}
}
On WindowsFormsApp2.exe:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
Then add a reference WindowsFormsApp2 to WindowsFormsApp1 so they will be at the same folder