value of a variable in a thread

  • Thread starter Thread starter ram s via .NET 247
  • Start date Start date
R

ram s via .NET 247

Hi

On the click of a button on the main form i call 4 threads(addressof class files) which do som process on different tablesin the db. I have variables in the threads which store value ofthe record being processed. How can i trap this value in themain form and display it so that the user knows the progress ofthe processing?

sample portion of my code:

Dim objDataProcess As New clsDataProcess

Dim processThrd As New Thread(AddressOf processEmp)

Private Sub btnSync_Click(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles btnSync.Click

processThrd.Start()

End Sub

Private Sub processEmp()
Dim rtnValC As String
rtnValC = objDataProcess.processEmp
End Sub

objDataProcess.processEmp is the function that actually processesthe records. let's say i have a variable recCount in it thatincrements with each record process. How i can access thisvariable in the main form?
 
I would create an event, which the thread fired and would, in your
example,
pass recCount as a parameter.

-----Izvirno sporoèilo-----
Od: ram s via .NET 247 [mailto:[email protected]]
Poslano: 23. maj 2005 5:41
Objavljeno v: microsoft.public.dotnet.languages.csharp
Pogovor: value of a variable in a thread
Zadeva: value of a variable in a thread

Hi

On the click of a button on the main form i call 4 threads (addressof
class files) which do som process on different tables in the db. I have
variables in the threads which store value of the record being
processed. How can i trap this value in the main form and display it so
that the user knows the progress of the processing?

sample portion of my code:

Dim objDataProcess As New clsDataProcess

Dim processThrd As New Thread(AddressOf processEmp)

Private Sub btnSync_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSync.Click

processThrd.Start()

End Sub

Private Sub processEmp()
Dim rtnValC As String
rtnValC = objDataProcess.processEmp
End Sub

objDataProcess.processEmp is the function that actually processes the
records. let's say i have a variable recCount in it that increments with
each record process. How i can access this variable in the main form?
 
ram s via .NET 247 said:
On the click of a button on the main form i call 4 threads (addressof
class files) which do som process on different tables in the db. I
have variables in the threads which store value of the record being
processed. How can i trap this value in the main form and display it
so that the user knows the progress of the processing?

See http://www.pobox.com/~skeet/csharp/threads/winforms.shtml

(Any reason for posting in the C# newsgroup if you're using VB.NET, by
the way?)
 
This solution could potentially be very dangerous. The event will fire on a thread other than the UI thread. If the event attempts to touch the UI the program will be broken (as this is not allowed in Windows Forms). Unfortunately, it will not be obviously broken as you will often get away with it for a time - but broken it is and it will fail at some point (normally when you have you manager or an investor in the room ;-) )

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

I would create an event, which the thread fired and would, in your
example,
pass recCount as a parameter.
 
Back
Top