Oh hi Mark
Oh hi Mark

Reputation: 203

My app keeps running in the processes after exit

I know this question is well asked and even better replied but i tried everything I found online and my winform app is still in the processes list in the task manager consuming RAM.

I'm using Quartz.NET and this is how I'm shutting down my app:

private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
        scheduler.Shutdown();
        scheduler2.Shutdown();
        Application.Exit();
    }

I'm using two schedulers. I tried killing the processes inside my app, I used FormClosing but it's still there.

Edit: Turns out the event of Form1_FormClosed wasn't called and i had to add it by the form properties.

Upvotes: 2

Views: 4454

Answers (2)

voytek
voytek

Reputation: 2222

There must be a thread that is still running. You can set all your threads as a background threads using Thread.IsBackground Property. You will be sure that all threads has ended when main thread ends

Calling in this case Environment.Exit(0); is a bad practice. I would try to investigate which thread has not ended and what's going on after close

Upvotes: 0

user586399
user586399

Reputation:

Most potential reason is: another thread (other than UI thread) is still running, and preventing the process from terminating. You can force the application to terminate the process at the FormClosed event using

Environment.Exit(0);

Because Application.Exit(); "tries" to exit the application normally, but the one in Environment class forces it to terminate immediately.

Upvotes: 7

Related Questions