c# close application code example

Example 1: c# how to exit program

System.Environment.Exit(1);

Example 2: c# how to close application

Environment.Exit(0);

Example 3: how to close an application in c#

this.Close();
//This only close the current form or window that you are using.

Example 4: how to close another app in system with c#

Process[] runningProcesses = Process.GetProcesses();
foreach (Process process in runningProcesses)
{
    // now check the modules of the process
    foreach (ProcessModule module in process.Modules)
    {
        if (module.FileName.Equals("MyProcess.exe"))
        {
            process.Kill();
        } else 
        {
         enter code here if process not found
        }
    }
}

Example 5: c# program exit

System.Windows.Forms.Application.ExitThread( )

Example 6: c# close window

Application.Exit();