Search code examples
c#visual-studioprocessformclosing

Process running on computer after application exit


I have a question, I created an application on visual studio using C# and Window Forms, but every time it runs, if the application close (either manually by the person or when it reach the end) it continue running on the process of the computer, so if I open and close the application 3 times there will be 3 processes with the same name activated. How can I prevent that from happening? So far the only way for me to close it is going to Window Task Manager and closing it manually, which is a pain...

Any ideas?


Solution

  • if you want to kill all processes and exit from application then first you need to kill threads in background

    Application.ExitThread();
    

    and then exit from application

    Environment.Exit();