Question

private void button1_Click(object sender, EventArgs e)
{
    Process p1 = new Process();
    p1.StartInfo.FileName
        = @"D:\Softwares\ftrScanApiEx_v3.2\ftrScanApiEx_v3.2\ftrScanApiEx.exe";
    p1.EnableRaisingEvents = true;
    p1.Exited += new EventHandler(p1_Exited);
    p1.Start();
}

private void p1_Exited(object sender, EventArgs e)
{
    Form3 f3 = new Form3();
    f3.Show();
    this.Hide();
}

Form3 is not loading even there is no error .. any idea why ???

Was it helpful?

Solution

I think, as indicated in the running comments, that this is indeed a threading issue. Invoke to the UI thread before creating Form3. Check the InvokeRequired and Invoke

private void p1_Exited(object sender, EventArgs e)
{
    if (this.InvokeRequired)
    {
        this.Invoke(new Action(OnProcessExited));
    }
    else
    {
        OnProcessExited();
    }
}

private void OnProcessExited()
{
    Form3 f3 = new Form3();
    f3.Show();
    this.Hide();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top