C#C
C#3y ago
The Joker

❔ Help to close a forms from another forms C#

I created 2 scripts with a timer with intervals of 1000 ms, both one is to open a new form when a certain process is started, this side is working fine, and the other is to close the same forms when the given process is closed, I've tried several times forms and I can't close the forms that were opened when the process is finished, could someone help me?

private void timer2_Tick(object sender, EventArgs e)
{
    Process[] processes = Process.GetProcessesByName("teste");

    if (processes.Length == 1)
    {
        frmTimer tm = new frmTimer();
        tm.Show();
        
        timer2.Stop();
    }
}

///


private void timer1_Tick(object sender, EventArgs e)
{
    Process[] processes = Process.GetProcessesByName("teste");

    if (processes.Length == 0)
    {
        frmTimer tm = new frmTimer();
        tm.Close();
       
        timer1.Stop(); 
    }
}
Was this page helpful?