Click here to Skip to main content
15,880,503 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Here's my code

C#
bool CloseInitiated = false;

 private void frmDashboard_FormClosing(object sender, FormClosingEventArgs e)
        {           
            if (CloseInitiated)
            {
                Application.ExitThread();
               
                Application.Exit();
            }
DialogResult dialogResult = MessageBox.Show("Are You Sure to Close AppPortal", "Close", MessageBoxButtons.YesNo);
            if (dialogResult == DialogResult.Yes)
            {
                CloseInitiated = true;

            }
            else if (dialogResult == DialogResult.No)
            {                
                e.Cancel = true;
            }
            if (CloseInitiated)
            {
              Process OrderProcess;              
              Process[] processesOrder=Process.GetProcessesByName("Orders");

                  if (processesOrder.Length > 0)
                    {                    
                        OrderProcess = processesOrder[0];
                        OrderProcess.Kill();
                        Application.Exit();
                        Application.ExitThread();
                        CloseInitiated = true;
                    }
             }
        }


When I press Close button It should ask a confirmation message then i need to Close the Process

How to Close all the forms
Posted
Comments
OriginalGriff 2-Sep-14 11:00am    
And what does it do?
Have you looks in the debugger?
KUMAR619 2-Sep-14 11:25am    
Sir, When I click No Nothing happens.
But When I click Yes.
The processes are closing but I am receiving the Yes Or No Dialog Box again
Rocker-Star 2-Sep-14 11:30am    
Can you check if the dialog box does not comes from the Orders process?

1 solution

I presume your query is how to close the Orders process (which is a seperate exe) from your application?
I can't see any issues with the code other than the process you are trying to stop from not actually closing down.
there is a method called
WaitforExit() 
which you can try.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900