Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
165
Problem exporting a pdf in a new thread
posted

Hi,

I am getting the usually error message: Object reference not set to an instance of an object, when iam trying to export a UltraGridWin.datasource to a pdf using using a System.timer.timer, but when i run the code not using a thread everyting works fine. It also works fine when iam exporting to an excel file.

Iam using netadvantage 7.3

(excel)

Me

 

.expExcelExporter.Export(Me.grdReport, strPathName)

 (pdf)

Me.expPdfExporter.UseFileBuffer = True
Dim bufferFileName As String = Path.Combine(strSavepath & "\", "ExportFileBuffer.tmp")
Me.expPdfExporter.FileBuffer = bufferFileName
Me.expPdfExporter.Export(Me.grdReport, strPathName, UltraWinGrid.DocumentExport.GridExportFileFormat.PDF)

 

 

System.NullReferenceException was caught
  Message="Object reference not set to an instance of an object."
  Source="Infragistics2.Win.v7.3"
  StackTrace:
       at Infragistics.Win.UltraWinMaskedEdit.MaskInfo.IsMaskModeDefined(MaskMode mode)
       at Infragistics.Win.UltraWinMaskedEdit.MaskInfo..ctor(EditorWithMask maskEditor, EmbeddableEditorOwnerBase owner, Object ownerContext)
       at Infragistics.Win.EditorWithMask.DataValueToText(Object valueToConvert, EmbeddableEditorOwnerBase owner, Object ownerContext)
       at Infragistics.Win.EditorWithMask.GetSize(EditorSizeInfo& sizeInfo)
       at Infragistics.Win.DateTimeEditor.GetSize(EditorSizeInfo& sizeInfo)
       at Infragistics.Win.EmbeddableEditorBase.GetSize(EmbeddableEditorOwnerBase owner, Object ownerContext, Boolean valueOnly, Boolean full, Boolean borders, Int32 maxTextWidth, Int32 height)
       at Infragistics.Win.UltraWinGrid.UltraGridColumn.CalculateCellTextWidth(UltraGridRow row, Graphics gr, StringFormat stringFormat, Int32 maxColWidth)
       at Infragistics.Win.UltraWinGrid.UltraGridColumn.TraverseRowsCallback.Infragistics.Win.UltraWinGrid.RowsCollection.IRowCallback.ProcessRow(UltraGridRow row)
       at Infragistics.Win.UltraWinGrid.RowsCollection.InternalTraverseRowsHelper(UltraGridBand band, IRowCallback rowCallback, IRowsCollectionCallback rowsCollectionCallback, Boolean recursive, Boolean includeTemplateAddRows)
       at Infragistics.Win.UltraWinGrid.UltraGridColumn.CalculateMaxCellTextWidth(Int32 maxColWidth, RowsCollection rows, Int32 nRows, Int32 maxRowsCollections)
       at Infragistics.Win.UltraWinGrid.UltraGridColumn.PerformAutoResizeHelper(RowsCollection rows, Int32 nRows, Boolean applyWidth, Boolean includeHeader, Boolean includeCells, Int32 maxRowsCollections)
       at Infragistics.Win.UltraWinGrid.UltraGridColumn.PerformAutoResizeHelper(RowsCollection rows, Int32 nRows, Boolean applyWidth, Boolean includeHeader, Boolean includeCells)
       at Infragistics.Win.UltraWinGrid.UltraGridColumn.PerformAutoResize(PerformAutoSizeType autoSizeType, Boolean includeHeader)
       at Infragistics.Win.UltraWinGrid.UltraGridColumn.PerformAutoResize(PerformAutoSizeType autoSizeType)
       at Infragistics.Win.UltraWinGrid.DocumentExport.UltraGridDocumentExporter.PrepareLayoutBeforeBeginExport(UltraGridLayout exportLayout)
       at Infragistics.Win.UltraWinGrid.DocumentExport.UltraGridDocumentExporter.BeginExportInternal(UltraGridExporterHelper ultraGridExporterHelper, UltraGridLayout exportLayout, RowsCollection rows)
       at Infragistics.Win.UltraWinGrid.DocumentExport.UltraGridExporterHelper.Infragistics.Win.UltraWinGrid.IUltraGridExporter.BeginExport(UltraGridLayout exportLayout, RowsCollection rows)
       at Infragistics.Win.UltraWinGrid.UltraGrid.Export(IUltraGridExporter exporter)
       at Infragistics.Win.UltraWinGrid.DocumentExport.UltraGridDocumentExporter.Export(UltraGrid grid, ISection section)
       at Infragistics.Win.UltraWinGrid.DocumentExport.UltraGridDocumentExporter.Export(UltraGrid grid, Report report)
       at Infragistics.Win.UltraWinGrid.DocumentExport.UltraGridDocumentExporter.Export(UltraGrid grid, String fileName, GridExportFileFormat fileFormat)
       at TestProsjekt.frmDokumentExporter.GeneratePDFandSendEmails(Object source, ElapsedEventArgs e) in C:\utvikling\TestProsjekt\TestProsjekt\Form1.vb:line 113
  InnerException:

  • 469350
    Suggested Answer
    Offline posted

    You cannot do this using a separate thread. The DocumentExporter will attempt to access the grid and the data on the UI Thread and this will result in unmarshalled calls across the threads which is very dangerous and will almost certainly cause errors.

    The only safe way to do this would be to create a new grid, and new data source, and a new DocumentExported all on the same thread and then do the export.