Async method

6 posts, 1 answers
  1. CarlosLima
    CarlosLima avatar
    47 posts
    Member since:
    May 2010

    Posted 22 Nov 2010 Link to this post

    Hi.
    Since I have to process a document before printing or saving it as doc or pdf (to convert inlineui to span text), I'm trying to do it all on a backgroundworker to avoid locking UI.

    Unfortuntantly I'm getting an exception on the format provider export (wich is called during the background code).

    I have a variable with the Raddocument and I'm converting it to xaml using:
    public static string GetXamlFormDocument(RadDocument document)
           {
               IDocumentFormatProvider exporter = new XamlFormatProvider();
               string result;
               using (MemoryStream stream = new MemoryStream())
               {
                   exporter.Export(document, stream);
                   stream.Seek(0, SeekOrigin.Begin);
                   StreamReader reader = new StreamReader(stream);
                   result = reader.ReadToEnd();
               }
               return result;
           }

    the cross-thread exception occours on the line exporter.Export(document, stream);

    Is there any way to solve this?

    Thanks,
    Carlos
  2. CarlosLima
    CarlosLima avatar
    47 posts
    Member since:
    May 2010

    Posted 23 Nov 2010 Link to this post

    Even using :
    public static string GetXamlFormDocument(RadDocument document)
    {
    return new XamlFormatProvider().Export(document);
    }
    I still get cross-thread exception.. I don't understand because document is a variable and even being created on the ui thread it's not a control so it should be accessible.
    Unless the problem is actually with the xamlformatprovider...

    What I'm trying to do and I'm sure others have tried is to print and save the files but have a busy window on the screen while this happens. To make that possible, the code for saving or printing has to be run on another thread to avoid locking the UI.

    Any idea how this can be accomplished?

    Thanks, Carlos
  3. DevCraft banner
  4. Answer
    Boby
    Admin
    Boby avatar
    595 posts

    Posted 25 Nov 2010 Link to this post

    Hi Carlos,
    You are right, there is a bug in XamlFormatProvider that causes UnauthorizedAccessException ("Invalid cross-thread access.") when Export method is called from another thread. This will be fixed immediately and will be available to you in the next LIB (latest internal build).
    Points in your Telerik account has been updated in appreciation.

    Greetings,
    Boby
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  5. CarlosLima
    CarlosLima avatar
    47 posts
    Member since:
    May 2010

    Posted 25 Nov 2010 Link to this post

    Thank you very much for your reply.
    Carlos
  6. Morne
    Morne avatar
    1 posts
    Member since:
    Jul 2012

    Posted 18 Jul 2012 Link to this post

    I've just upgraded to version 2012.2.607.1040 of RadControls for Silverlight, and I still get the same cross-thead exception error with the HTML Format provider in Telerik.Windows.Documents.FormatProviders.Html.dll when trying to Import a string to HTML
  7. Boby
    Admin
    Boby avatar
    595 posts

    Posted 23 Jul 2012 Link to this post

    Hello Morne,
    Actually Carlos's question was about the exporting rather that importing. Importing wouldn't work as there are some dependencies between the document model and UI elements, which (UIElements) cannot be created in background thread. We have plans to decouple these and enable this scenario, but there is nothing scheduled yet.

    Kind regards,
    Boby
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft banner