0

I'm trying a new approach to keeping my UI responsive while loading an large xps document. My button click starts my progress bar (loadStatus) I then start a new thread and call my "open and view document" method. The UI runs and the progress bar does it's thing but the xps document never displays. Before trying the code below, I ran the method on it's own right in the button click event and it works just fine. But as you know, the progress bar does nothing until the doc loads and is displayed. So, here is my code snippet, any ideas on what I may be doing wrong? I apologize in advance if I left anything out in my question post. Here's my code snippet:

private void maintBtn_TouchDown(object sender, TouchEventArgs e) // load and view maint manual
{
    loadStatus.IsIndeterminate = true;
    Thread thread = new Thread(getMaintDocument);
    thread.Start();  
}

private void getMaintDocument() // get and view the document
{
   XpsDocument xpsDocument = new XpsDocument(@"Resources\maintManual.xps", FileAccess.Read); 
   documentViewer1.Dispatcher.Invoke(new Action(()=> xpsDocument.GetFixedDocumentSequence()) ,DispatcherPriority.Normal);  
}
  • sorry some of the code above is not displaying right but I think you get the idea – user6505984 Aug 31 '16 at 18:25
  • The problem is that your xps document contains UI elements, and UI elements are thread-centric. I'm surprised it didn't throw. I don't believe there is any way around this other than constructing the document on the UI thread, unfortunately... –  Aug 31 '16 at 18:36
  • Thank you Will for your input. I will plug along. Thanks again man – user6505984 Aug 31 '16 at 20:36

0 Answers0