Forgive me if I sound a bit stupid
I am using the DotNetBar componant 'SuperTab' which is basically a tab control
(Not really relevent but Im setting the scene)
I have 5 seperate 'Subs' that create a tab and display a crystalreportviewer
These are working great individually, but when I run all 5 on the form load, it obviously takes a few seconds for everything to run.
So... I thought I would have a go at my first 'threat' and see if I can get all 5 to run symultaniously.
Im using seperate Backgroundworkers, and for each one the 'RunWorkerAsync calls the individual Subs to get all 5 to run
I am hitting across the error
'Control accessed from a thread other than the thread it was created on.'
when each worker is called
Ive done some googling, and tried a number things but I cannot get it to work.
The one that seemed the most successful was:
But when that runs it tells me it cant call a disposed object.Code:Private Sub CreateInvoiceOnlyTab()
If Me.InvokeRequired Then
Me.Invoke(New MethodInvoker(AddressOf CreateInvoiceOnlyTab))
Else
'Rest of the Sub code goes here
So now Im stuck
This is the code without any threading elements:
This code runs perfectly when called as a normal subCode:Private Sub CreateInvoiceOnlyTab()
Dim newTab As SuperTabItem = SuperTabControl1.CreateTab("Standard Invoice")
Dim panel As SuperTabControlPanel = DirectCast(newTab.AttachedControl, SuperTabControlPanel)
Dim crviewer As New CrystalReportViewer
panel.Controls.Add(crviewer)
crviewer.Dock = DockStyle.Fill
crviewer.ToolPanelView = ToolPanelViewType.None
'Generate Report
Dim report As DaMtechInvoice = New DaMtechInvoice
Dim crParameterDiscreteValue As ParameterDiscreteValue
Dim crParameterFieldDefinitions As ParameterFieldDefinitions
Dim crParameterFieldLocation As ParameterFieldDefinition
Dim crParameterValues As ParameterValues
'
' Get the report parameters collection.
'
'crystalreportspartsviewer()
crParameterFieldDefinitions = report.DataDefinition.ParameterFields
' Add a parameter value - START
crParameterFieldLocation = crParameterFieldDefinitions.Item("PARAM1")
crParameterValues = crParameterFieldLocation.CurrentValues
crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
crParameterDiscreteValue.Value = InvoiceID
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
' Add a parameter value - END
crParameterFieldLocation = crParameterFieldDefinitions.Item("PARAM2")
crParameterValues = crParameterFieldLocation.CurrentValues
crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
crParameterDiscreteValue.Value = InvoiceID
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
crParameterFieldLocation = crParameterFieldDefinitions.Item("PARAM3")
crParameterValues = crParameterFieldLocation.CurrentValues
crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
crParameterDiscreteValue.Value = ClientID
crParameterValues.Add(crParameterDiscreteValue)
crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
crviewer.ReportSource = report
End Sub
Thanks in advance
Matt
