locked
Silverlight Background Rendering RRS feed

  • Question

  • Hello,

    I've got a fairly complex rendering job (e.g. rendering a PDF or HTML file) into a ContentPresenter. I'm trying to do the rendering in a BackgroundWorker. The idea is to do the rendering, which could take some time and not block the UI thread - part of the rendering includes fetching remote items (e.g. jpgs etc). The plan is to render in the background and once the Canvas is done, add it to a ContentPresenter.

    The problem is whenever I create a UIElement (e.g. new Paragraph(), new RichTextBox() etc), I get the dreaded cross thread violation exception. I'm only creating the UIElement (and haven't *added* it to anything in the UI Visual Tree yet) and I still get this exception.

    Could anyone please point me in the derection where I can build visual elements in a background thread and defer additing them to the UI Visual Tree? Is this even possible?

    Thanks,

    Narayan

    Wednesday, November 3, 2010 10:38 PM

Answers

  • You cannot render UI in the background thread, period.  That is simply not an option.

    However, Jpg download is async, and you are not blocking the UI just because you are downloading a large Jpg.

    Wednesday, November 3, 2010 11:09 PM
  • Thanks for responding.

    As it turns out, there is a way....One can render content to a string in the background thread and then use System.Windows.Markup.XamlReader.Load to generate the necessary UI. Not ideal but good to know that there is an alternative.

    Thursday, November 4, 2010 4:18 PM

All replies

  • You cannot render UI in the background thread, period.  That is simply not an option.

    However, Jpg download is async, and you are not blocking the UI just because you are downloading a large Jpg.

    Wednesday, November 3, 2010 11:09 PM
  • Thanks for responding.

    As it turns out, there is a way....One can render content to a string in the background thread and then use System.Windows.Markup.XamlReader.Load to generate the necessary UI. Not ideal but good to know that there is an alternative.

    Thursday, November 4, 2010 4:18 PM