1

After pressing the 'x' button in a window, the contents of my window black out and then I have to press the 'x' a second time to close down the program completely. Anyone know why this is?

MrBretten
  • 27
  • 7

1 Answers1

3

This is how Windows behaves when an application is not responding. I'm guessing you have some work ongoing in the main UI thread that is blocking the Form from responding to the Close event.

When you are performing a long-running operation in WinForms you should consider using a BackgroundWorker. This will allow the Form to update and respond correctly.

-- edit --

Sorry just saw you are in WPF not WinForms. Same principal applies though. See also this question: How to use WPF Background Worker

Community
  • 1
  • 1
csharptest.net
  • 62,602
  • 11
  • 71
  • 89