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

RadDocument processing in Background processes

3 Answers 187 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 12 Feb 2013, 05:03 PM

Hi Telerik,

I have a few questions regarding the usage of the RadDocument.  According to my scenario I prepare different Documents in Designer (using RadRichTextBox) with Placeholders,  which are implemented with the InlineUIContainers and child TextBlock element,  and then this serialize document to HTML and retain in the Storage.
In the various Application background processes we use the prepared Doument "template" for generating HTML documents,  by replacing the Placeholders with the real-time data.
To do it, we 
try to deserialize the RadDocument from the HTML and then use RadDocument DOM model for easier and safer Placeholder replacement operation.  The only way we found to do it on Application Server is to use methods  HtmlFormatProvider.Import, HtmlFormatProvider.Export. BUT they are not designed to be used in a such way as they expect to be run only in STA thread, so we got an exception:

InvalidOperationException with message "The calling thread must be STA, because many UI components require this."

Creating a dedicated STA thread for processing each documents works only under non-stressful conditions, and definitely failed on contrary with the confusing exception:

System.ComponentModel.Win32Exception (0x80004005): The operation completed successfully

Could you please suggest any way to overcome our problem, or suggest another approach for working with RadDocuments in background processes?

 

Thanks

3 Answers, 1 is accepted

Sort by
0
Boby
Telerik team
answered on 13 Feb 2013, 07:33 AM
Hi Alex,
Unfortunately this is known issue with RadDocument, caused by the fact that in the current implementation document model is coupled with some UI elements. We have plans to improve this and allow usage of the format providers in MTA threads, as well as in multi-threading scenarios, but for now it's not clear when this will be implemented. Until then, you only options is to use RadDocument in STA thread.

We have previous reports of "The operation completed successfully" exception and it seems that it is caused by an issue in .NET framework. You can try if the workaround suggested in the thread works for you:

You can work around this bug by adding the following code to your thread proc:
Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
dispatcher.BeginInvokeShutdown(DispatcherPriority.Normal);
Dispatcher.Run();
This asks the dispatcher associated with the thread to shut down right away.



Don't hesitate to contact us if you have other questions.


Kind regards,
Boby
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Jeff
Top achievements
Rank 1
answered on 12 Dec 2013, 04:17 PM
Hello, has this change been applied in any of the recent versions, or is there a place that I can track this feature's progress? 
0
Petya
Telerik team
answered on 14 Dec 2013, 11:57 AM
Hello Jeff,

The change was introduced in our latest official version. There is also an example of this in our SDK demos (you can find the demo here as well).

Let me know if you have any other questions.

Regards,
Petya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
RichTextBox
Asked by
Alex
Top achievements
Rank 1
Answers by
Boby
Telerik team
Jeff
Top achievements
Rank 1
Petya
Telerik team
Share this question
or