0

I have exit command:

void CloseMethod() { //Application.Current.Shutdown(); Environment.Exit(0); } 

The problem is that when I click the button it hides the GUI but I still see the app open at the task manager same with Application.Current.Shutdown();

6
  • So on button click you want to close the application? Is it Winform? Commented Mar 26, 2019 at 11:40
  • @Rahul it's in wpf Commented Mar 26, 2019 at 11:44
  • @Jan but why the app still open at tak manager??? Commented Mar 26, 2019 at 11:47
  • sorry, didn't know it was WPF. for WPF the answer should be this one: stackoverflow.com/questions/2820357/… Commented Mar 26, 2019 at 11:49
  • Are you sure the process shown in Task Manager is not an old instance, before you made your most recent changes? Commented Mar 26, 2019 at 11:58

2 Answers 2

0

You would want to call Application.Exit(); rather which would terminates all message loops and closes all windows, giving your forms the possibility to execute their cleanup code. See Application.Exit for more information. Quoting from documentation

Informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed.

For WPF you should call Application.Current.Shutdown(); but read the documentation which clearly says that Shutdown() method should be called from Main() method cause that's the entry point from where Application instance got created

Sign up to request clarification or add additional context in comments.

Comments

-2

Are you using any threads in the application ? In case you are, make sure you stop all the threads before exiting the application. I don't normally prefer the .abort command, but you can try using

th.Abort(); //th is the name of the thread 

before you use Environment.Exit(0)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.