Linked Questions

Popular Questions

C# - Wait for process to exit and close 'ShowDialog()'

Asked by At

Being new to .net, i am not able to get how to close the show dialog modal window once its open. As i have learnt we cannot close that automatically until explicitly its to be called. Here is my code:

//process - notepad.exe 
Process p = Process.Start(process); 
frm_Save fsave = new frm_Save(); 

Using (p)
{ 
    do
    { 
        if(!p.HasExited)    
        {
            p.Refresh();
            fsave.ShowDialog(); // it just stuck here and doesn't go to next line
        }
    } 
    while(!p.WaitForExit(1000)); 
}

//frm_Save.cs 
public frm_Save() 
{ 
    InitializeComponent(); 
}

private void frm_Save_Load(...,....)
{ 
    // 
}

private void frm_Save_Shown(...,...) 
{ 
    Sleep(100); 
    Forms.Application.DoEvents();
    Close(); 
}

Related Questions