Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a Thread to a Method?

Status
Not open for further replies.

nomi2000

ISP
Feb 15, 2001
676
0
0
CA
Hi
I have a long process (method) say "ShowReport" which is taking much time for getting data from back-end and show it as a REPORT in CRYSTAL REPORT .what i want is to run this process as a new thread so it will fetch data and i want to show a blinking label which will say "Processing Data"
I have written this Code but no Report is popping up..can anybody tell what i am doing wrong?
Regards
Nouman

Private Sub btnReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport.Click

lblProgress.Visible = True
tmrProgress.Enabled = True

Dim t As Thread
t = New Thread(AddressOf Me.ShowReport)
t.Start()

lblProgress.Visible = False
tmrProgress.Enabled = False
End Sub
Private Sub ShowReport()
Dim objReport As New ReportObject
Dim myParam As New Collection
Dim strBuildSQL As String
strBuildSQL = BuildSQL()
myParam.Add(strBuildSQL)
objReport.ParamCollection = myParam
objReport.ShowReport("E")

End Sub

Private Sub tmrProgress_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrProgress.Tick
If Me.lblProgress.ForeColor.ToArgb <> Me.lblProgress.BackColor.ToArgb Then
Me.tmrProgress.Interval = 250
Me.lblProgress.ForeColor = Me.lblProgress.BackColor
Else
Me.tmrProgress.Interval = 1000
Me.lblProgress.ForeColor = Color.Black
End If

End Sub

Nouman Zaheer
Software Engineer
MSR
 
Try

If Me.lblProgress.ForeColor.ToArgb <> Me.lblProgress.BackColor.ToArgb Then
Me.tmrProgress.Interval = 250
Me.lblProgress.ForeColor = Me.lblProgress.BackColor
Else
Me.tmrProgress.Interval = 1000
Me.lblProgress.ForeColor = Color.Black
End If

Me.lblProgress.Refresh

Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
hi john
thanks for repoly but the problem is not with refreshing the label the problem is with that the crystal report viewer is shown at once and then dissapear it seems that that thread in which i called the "Show Report" method died and doesn't retain in the memory how i can tell the application to treat the thread for "Show Report" as the current thread ?
Regards
Nouman


Nouman Zaheer
Software Engineer
MSR
 
The variable which holds the reference to your report is going out of scope and being GC'd when your 2nd thread ends. You need to pass it back to your original thread after it gets created.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Hi cliph
thanks how i will do this? how i will pass the reference of the report to the 2nd thread? any suggestion to change the above code?
Thanks
Nouman

Nouman Zaheer
Software Engineer
MSR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top