This is a migrated thread and some comments may be shown as answers.

Async method

5 Answers 103 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
CarlosLima
Top achievements
Rank 1
CarlosLima asked on 22 Nov 2010, 11:41 PM
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

5 Answers, 1 is accepted

Sort by
0
CarlosLima
Top achievements
Rank 1
answered on 23 Nov 2010, 10:45 PM
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
0
Accepted
Boby
Telerik team
answered on 25 Nov 2010, 02:51 PM
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
0
CarlosLima
Top achievements
Rank 1
answered on 25 Nov 2010, 09:23 PM
Thank you very much for your reply.
Carlos
0
Morne
Top achievements
Rank 2
answered on 18 Jul 2012, 11:38 AM
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
0
Boby
Telerik team
answered on 23 Jul 2012, 08:01 AM
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.

Tags
RichTextBox
Asked by
CarlosLima
Top achievements
Rank 1
Answers by
CarlosLima
Top achievements
Rank 1
Boby
Telerik team
Morne
Top achievements
Rank 2
Share this question
or