title: WPF DocumentViewer: Switching between windows makes the window as if it has crashed
body: <p>I have a WPF application with a custom control, based on DocumentViewer. There is a "Print" button, which leads to printer selection dialog. When I select a certain printer ("novaPDF Lite Server v7") and then press the "Print" button, a dialog box with printer settings is displayed. That dialog box appears in the task bar as a separate application.</p>
  
  <p>When I activate that printer dialog, then activate some other application and then switch back to the WPF application, its client are (everything below the title bar) is white. It looks as if it hangs.</p>
  
  <p><img src="https://i.stack.imgur.com/bYqHL.png" alt="enter image description here"></p>
  
  <p>When I close the printer settings dialog, the WPF application starts to look in the normal way (all the controls are there).</p>
  
  <p>I suppose that the problem is caused by the way the print process is started. Maybe it can fixed by doing the printing in a separate thread.</p>
  
  <p>Here's how it is done now:</p>
  
  <pre><code>using System.Printing;
  using System.Threading;
  using System.Windows;
  using System.Windows.Controls;
  
  namespace MyControls
  {
    public class MyDocumentViewer : DocumentViewer
    {
      [...]
      protected override void OnPrintCommand()
      {
          base.OnPrintCommand();
          this.FirePrintFinished();
      }
      [...]
    }
  </code></pre>
  
  <p>What can I do in order to fix the problem?</p>
  
  <p><strong>Update 1 (03.09.2013):</strong> Changing the <code>MyDocumentViewer</code> so that printing is done asynchronously didn't help.</p>
  
  <pre><code>namespace MyControls
  {
    public class MyDocumentViewer : DocumentViewer
    {
      [...]
      protected override void OnPrintCommand()
      {
          var worker = new PrintWorker(this);
          Dispatcher.Invoke(new Action(worker.DoWork));
      }
      public void OnPrintCommandBase()
      {
          base.OnPrintCommand();
      }
  
      [...]
      }
  
      public class PrintWorker
      {
          private readonly MyDocumentViewer _myDocumentViewer;
  
          public PrintWorker(MyDocumentViewer myDocumentViewer)
          {
              _myDocumentViewer = myDocumentViewer;
          }
  
          public void DoWork()
          {
              _myDocumentViewer.OnPrintCommandBase();
              _myDocumentViewer.FirePrintFinished();
          }
      }
  
    }
  </code></pre>
  
  <p><strong>Update 2 (05.09.2013):</strong> The problem can only be reproduced, when I access the machine with the application via Remote Desktop (it does not occur, if I run the program locally).</p>