Reputation: 53
When i try to close my current window, i use:
this.Close();
and it succesfully closes the window. But in background, the window's operation is running also. I mean, i close window but cannot stop its operations, such as for loop. It continues to operate for process.
Upvotes: 2
Views: 210
Reputation: 6524
When you close the window, you are asking the GUI thread to accomplish its operations. However, those processes which are carried out in a different thread such as web requests, and other asynchronous operations run in their own thread.
If you are running the loop in a different thread then it is quite possible that it will not terminate itself when you close the window.
WPF performs many of its operations asynchronously so go through the code of your window and see if there is anything which needs explicit termination.
Further, terminating the loop abnormally is not a good idea. If you are running a loop, put a break condition which stops the loop when you terminate the window.
Upvotes: 1
Reputation: 6586
I doubt there's a mechanism for this built into the library: it is asking for problems with incorrectly released resources. Instead, add a guard into any long-running processes, something like
if(isClosing) break;
Then set isClosing
to true
in the Closing
event handler.
Upvotes: 1