In Development
Last Updated: 08 Mar 2019 12:39 by ADMIN
Created on: 20 Mar 2018 07:02
Category: RichTextBox
Type: Bug Report
RichTextBox: Win32Exception is thrown when RadDocuments are processed in background threads
"Win32Exception (0x80004005): Not enough storage is available to process this command" is thrown when multiple RadDocument instances are created in background threads. 

This is due to the fact that RadDocument contains MailMergeDataSource object, which is DependencyObject. When multiple dependency objects are created in different threads, they are not property freed by thread's Dispatcher.

Workaround 1: Microsoft provided workaround in a bug report here: , namely:
Put the following code:

Dispatcher dispatcher = Dispatcher.CurrentDispatcher;

anywhere in the background thread processing the RadDocument.

Workaround 2: Use pooling of the used threads. The problem is that Task Parallel Library (which has built-in pooling) does not use STA threads by default, but this can be achieved by using custom TaskScheduler (attached, the code is get from here: ):

            var parallelOptions = new ParallelOptions()
                TaskScheduler = new StaTaskScheduler(Environment.ProcessorCount)

            Parallel.For(0, 10000, parallelOptions, cc =>
                    var document = new DocxFormatProvider().Import(data);
                    byte[] pdfBytes = new PdfFormatProvider().Export(document);