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

Error exporting from excel and merging PDF documents

1 Answer 187 Views
SpreadProcessing
This is a migrated thread and some comments may be shown as answers.
Lars
Top achievements
Rank 1
Lars asked on 27 Aug 2019, 08:59 AM

Hi, 

We have a threaded service where we export excel documents to PDF documents (using Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider.Export) and then merge the PDF with other PDF documents (using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider.Import and RadFixedDocument.Merge). We make sure to dispose the Workbook of the excel document and the MemoryStream from exporting to PDF. 

After some time we start getting the following error, until we restart the service.

One or more errors occurred.
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Telerik.Windows.Documents.Utilities.TasksHelper.DoAsync(Action[] actions)
   at Telerik.Windows.Documents.Spreadsheet.Layout.RadWorksheetLayout.CalculateCellContentSizes(List`1 cellsToCalculateContentSize, CellProperties[] cellsFontProperties)
   at Telerik.Windows.Documents.Spreadsheet.Layout.RadWorksheetLayout.UpdateCellContentSizesCache()
   at Telerik.Windows.Documents.Spreadsheet.Layout.RadWorksheetLayout.Measure()
   at Telerik.Windows.Documents.Spreadsheet.Model.Workbook.UpdateWorksheetLayout(RadWorksheetLayout worksheetLayout, Worksheet worksheet, Boolean isForPrinting)
   at Telerik.Windows.Documents.Spreadsheet.Model.Shapes.ShapeCollection.GetTopLeftPoint()
   at Telerik.Windows.Documents.Spreadsheet.Model.Shapes.ShapeCollection.GetTopLeftCellIndex()
   at Telerik.Windows.Documents.Spreadsheet.Model.Shapes.ShapeCollection.RecalculateUsedCellRange()
   at Telerik.Windows.Documents.Spreadsheet.Model.Worksheet.get_TotalUsedCellRange()
   at Telerik.Windows.Documents.Spreadsheet.Layout.PageLayout.AddPages(Worksheet worksheet, Boolean ignorePrintArea)
   at Telerik.Windows.Documents.Spreadsheet.Layout.PageLayout.PreparePages(Workbook workbook, Boolean ignorePrintArea)
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider.ExportOverride(Workbook workbook, Stream output)
   ...
   ...
 Inner exception: The operation completed successfully
    at MS.Win32.UnsafeNativeMethods.RegisterClassEx(WNDCLASSEX_D wc_d)
    at MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)
    at System.Windows.Threading.Dispatcher..ctor()
    at System.Windows.Threading.Dispatcher.get_CurrentDispatcher()
    at System.Windows.Media.TextFormatting.TextFormatter.FromCurrentDispatcher(TextFormattingMode textFormattingMode)
    at System.Windows.Media.FormattedText.LineEnumerator..ctor(FormattedText text)
    at System.Windows.Media.FormattedText.DrawAndCalculateMetrics(DrawingContext dc, Point drawingOffset, Boolean getBlackBoxMetrics)
    at System.Windows.Media.FormattedText.get_Metrics()
    at Telerik.Windows.Documents.Core.TextMeasurer.RadTextMeasurer.MeasureTextWithWrapping(TextProperties textProperties, FontProperties fontProperties, Double wrappingWidth)
    at Telerik.Windows.Documents.Spreadsheet.Measurement.RadTextMeasurer.Measure(String text, FontProperties fontProperties, Nullable`1 wrappingWidth)
    at Telerik.Windows.Documents.Spreadsheet.Measurement.RadTextMeasurer.MeasureMultiline(String text, FontProperties fontProperties, Nullable`1 wrappingWidth)
    at Telerik.Windows.Documents.Spreadsheet.Layout.LayoutHelper.DefaultTextMeasuringMethod(String text, FontProperties fontProperties, Nullable`1 wrappingWidth)
    at Telerik.Windows.Documents.Spreadsheet.Layout.LayoutHelper.CalculateCellContentSize(ICellValue cellValue, CellValueFormat format, FontProperties fontProperties, Double cellIndent, Nullable`1 wrappingWidth, Func`4 measureMultilineText)
    at Telerik.Windows.Documents.Spreadsheet.Layout.RadWorksheetLayout.<>c__DisplayClass4.<CalculateCellContentSizes>b__1()
    at System.Threading.Tasks.Task.Execute()

 

Any help on why this happens and how we can fix it would be appreciated. 

1 Answer, 1 is accepted

Sort by
0
Boby
Telerik team
answered on 29 Aug 2019, 07:04 AM

Hello Per,

We have similar reports in the past, so I will describe the possible problem - let us know if your scenario is different.

The implementation uses some .NET Framework classes which internally creates Dispatcher class instances and starts them. Each dispatcher is associated with a specific thread, and if a lot of threads are created, they have a lot of running Dispatcher-s in them, and there is no built-in mechanism to stop them. 

As a workaround, you can:

- use thread pooling, ensuring that the same threads are reused, or

- explicitly invoke dispatcher shutdown somewhere in the code for the thread:

Thread thread = new Thread(() =>
{
    // Thread logic
    Dispatcher.Current.BeginInvokeShutdown ();
});

Let us know if any of these would work for you.

Regards,
Boby
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
SpreadProcessing
Asked by
Lars
Top achievements
Rank 1
Answers by
Boby
Telerik team
Share this question
or