Sonic Soul
Sonic Soul

Reputation: 24909

WPF: program.exe doesn't exit "the process cannot access the file.. used by another process"

I've worked on quite a few WPF solutions, and this is the first time i am seeing this problem.

Today it started happening intermittently. where after closing my WPF window, the .exe is still running under visual studio.

so i have to kill my program.exe manually in order to compile again.

Initially i thought because i overrode application start/exit/exception .. but i commented all that out, and it is still happening.

In fact, i see multiple instances of my program.exe in process explorer!

Can't figure out what is causing my exe not to exit. Is there any explicit dipose logic i can add in applicaton exit event to ensure it really exits?

My application consists of single window, and multiple user controls as views.

update

if i open in debug mode. and close the main WPF window, my visual studio does not stop debugging. however call stack window is empty.

Upvotes: 2

Views: 2389

Answers (2)

CodeNaked
CodeNaked

Reputation: 41393

You can use the Application.Exit event to log when your application shuts down.

Alternatively, you can attach the debugger to your running instance (even if it wasn't started in the debugger) then pause it to see where it's at. Make sure to look at the Threads tool window, as you may pause outside the UI thread.

Upvotes: 1

ceyko
ceyko

Reputation: 4852

This should take care of it, though its probably better to try to figure out the underlying issue.

System.Diagnostics.Process.GetCurrentProcess().Kill();

Upvotes: 0

Related Questions