We have a simple method looking like this:
public void DisplayPrintDialog(Document document)
{
try
{
PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog() ?? false)
{
...
}
}
catch (Exception exc)
{
LogEx.Error(string.Format(LogMessages.ErrorPrintDialog, exc));
MessageBox.Show(string.Format(ErrorMessages.PrintDialog, exc.Message), AppStrings.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
Now the following happens.
We open the dialog and select a printer that is NOT available at that moment (i.e. missing vpn connection, etc.).
There is (not on my development mashine, but at least on our test system) a message that he tries to connect to the printer and this seems not to be successful, but does not create an error either, so it runs forever (don’t know how high the timeout is set here).
Then we click in the dialog on Cancel
.
Now we close the application and get the MessageBox
from inside the method which bubbles to the unhandled exception handler in the app.xaml.cs.
So even if the PrintDialog
is already closed and the method should have been left the handle on this dialog is not released it seems. There is no dispose, no CancellationToken or something the like what I could use to be sure it is released. Anyone an idea how to prevent the error message? (Except for killing the catch of course) Can I put the dialog in the garbage collector by hand maybe when it is cancelled?