I am encountering an odd issue with a thread in vb.NET. I'm using the visual studio 2003 IDE with the .NET 1.1 framework.
The problem is that, upon returning from a thread, a crystal report object I've created seems to have all of it's internal members set to nothing. The report object itself isn't set to nothing, just the internal members. Also, other report documents are created through the same code and do not cause this problem. Using the exact same code, but converting the project to VS 2005 and .NET 2.0, fixes the problem entirely. However, this isn't an option for us right now.
Here's a glimpse into the suspect code. This timer tick starts the thread. The thread's goal is to save a crystal report object in the form level object, oReportDocument:
A few things of interest to point out:
Any suggestions would be greatly appreciated,
Chuck
The problem is that, upon returning from a thread, a crystal report object I've created seems to have all of it's internal members set to nothing. The report object itself isn't set to nothing, just the internal members. Also, other report documents are created through the same code and do not cause this problem. Using the exact same code, but converting the project to VS 2005 and .NET 2.0, fixes the problem entirely. However, this isn't an option for us right now.
Here's a glimpse into the suspect code. This timer tick starts the thread. The thread's goal is to save a crystal report object in the form level object, oReportDocument:
VB.NET:
Public oReportDocument As ReportDocument
Public Delegate Sub SetReportDelegate(ByVal oReport as ReportDocument)
Private Sub tmrLoad_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrLoad.Tick
Dim oThread As System.Threading.Thread
' Disable load timer so we don't cascade loading windows
tmrLoad.Enabled = False
' Create a new thread with the routine that loads the report and start it
oThread = New Threading.Thread(AddressOf PerformLoadReport)
oThread.Start()
' While that thread is processing, process application events (ie, animation)
While oThread.IsAlive = True
Application.DoEvents()
End While
' Pass control back to main form now that we have a loaded report
' document.
oThread = Nothing
Me.Hide()
End Sub
' A routine meant to be run in a separate thread that will load a report
' document and pass it back to the form via function delegate.
Public Sub PerformLoadReport()
Dim oSetIt As SetReportDelegate
Dim oReport as ReportDocument
' We need to load a specific report at this point.
Select Case iReportToLoad
Case modGlobal.REPORT_COST_OF_LABOR
oReport = modCostOfLabor.LoadReport()
Case modGlobal.REPORT_FD_PRODUCTION
oReport = modFdProductivity.LoadReport()
Case modGlobal.REPORT_FD_PRODUCTION_BY_HOUR
oReport = modFdProductivityByHour.LoadReport()
Case modGlobal.REPORT_HOURLY_PRODUCTION
oReport = modHourlyProduction.LoadReport()
Case modGlobal.REPORT_REVENUE_PROJECTION
oReport = modRevenueProjection.LoadReport()
End Select
' Use delegate to set loaded report to the form object
oSetIt = AddressOf SetReportToForm
oSetIt.Invoke(oReport)
oSetIt = Nothing
Application.DoEvents()
End Sub
' This sub routine sets a report document to the form's report document.
' We map this to a delegate to updatge the form's report doc from a
' threaded environment.
Private Sub SetReportToForm(ByVal oReport as ReportDocument)
Me.oReportDocument = oReport
End Sub
A few things of interest to point out:
- If the report is loaded by any case other than "Case modGlobal.REPORT_COST_OF_LABOR", it works fine. That is the only instance causing the problem.
- The report document is valid up until the end of the PerformLoadReport routine
Any suggestions would be greatly appreciated,
Chuck
Last edited: