Invoking Procedures

leedo2k

Active member
Joined
Nov 9, 2006
Messages
28
Programming Experience
Beginner
Hello,

I am writing a program that assigns data sources to crystal report documents and assigns them to crystal report viewer on a Windows form. To make the UI responsive I chose to implement this inside new threads. My Sub does some database binding and then assigns the datasource to the crystal viewer which is naturally running in the UI main thread.

As usual, I had to use delegates and invoke. What I am doing is that I am checking whether the viewer is invoked before modifying its data source.

Please find below my code:
VB.NET:
    Private Sub ShowAllEmployees()



        Dim myDoc as New CrystalDecisions.CrystalReports.Engine.ReportDocument
	MyDoc= New rpt_Emps()


        'Fill Data Adapter Code
	EmpTableAdapter.FillBy_All_Employees(Me.DataSet.Employees)


        'Set Report Datasource Property
        rptDoc.SetDataSource(DataSet)

        'Assign the dataset to the report. Since this SUB is running in a separate thread from the UI. It must 
        'be(passed) to the UI main thread through a delegate.
        If CrystalViewer.InvokeRequired Then

            Dim newDelegate As New UIDelegate(AddressOf ShowAllEmployees)
            CrystalViewer.Invoke(newDelegate)

        Else

            CrystalViewer.ReportSource = rptDoc

        End If

    End Sub


Now my problem is that I noticed that every time an invoke is performed the SUB is called again and so doing the same job twice.:cool: This applies on modification that I might want to do on CrystalViewer. Is there a way to avoid this? :confused::confused: Thanks
 
Last edited:
If you call that method in a background thread the contents of the If block gets executed once on the background thread, the contents of the Else block gets executed once on the UI thread and everything else gets executed both times. If you have code that you only want executed once on the background thread, where do you suppose you should put it?
 
Back
Top