-1

I am new for c# developer and I tried to close my window application with following code. I hide close button of form and add user defined button to close application.

 private void closeBtn_Click(object sender, EventArgs e)
        {
            System.Environment.Exit(0);
            //Environment.Exit(1);
            //Application.Exit();
            //this.Close();
        }

But process still running on Task Manager. Actually I am calling this application from Window service. But application is not closing properly.

private void callback(Object state)
        {
    string strAppPath;
                        strAppPath = @"D:\VSPythonProject\Reminder_WApp\Reminder_WApp\bin\Debug\Reminder_WApp.exe"; //System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + 
                        System.Diagnostics.Process.Start(strAppPath);

                        ApplicationLoader.PROCESS_INFORMATION procInfo;
                        ApplicationLoader.StartProcessAndBypassUAC(strAppPath, out procInfo);
    }
siksha
  • 128
  • 7

1 Answers1

1

check ApplicationLoader event. That call twice.

For closing application use below code :

System.Windows.Forms.Application.Exit();

instead of

System.Environment.Exit(0);

To close running threads use:

System.Windows.Forms.Application.ExitThread( );

To close running form use :

this.close();

For console application use:

System.Environment.Exit(0);
Jaimesh
  • 841
  • 4
  • 25
  • 41
  • 1
    Now application closing because I had mistake in service. I called application two time. System.Diagnostics.Process.Start(strAppPath); I comment this line in service. – siksha Jul 06 '17 at 11:52
  • Ok. I have update my answer. – Jaimesh Jul 07 '17 at 07:11