|
-
Nov 14th, 2002, 08:04 AM
#1
Thread Starter
Lively Member
Variables and Threading
Ok, here is my dilemma. I have a multi-threaded application using threadpooling that spawns multiple threads as needed. Inside my sub-routine I have a variable named strCounter. The problem is, when more than one thread gets called it is sharing the strCounter variable. How can I keep the variable unique to that thread so that it does not get incremented from other threads. I am diming the variable in the main class as Private which does not appear to help.
Here is a example:
Public Class Main
Private strCounter as integer
Sub Timer
While oDataReader.Read()
ThreadPool.QueueUserWorkItem(AddressOf Reboot, oDataReader("Server") & "|" & oDataReader("PKey") & "|" & oDataReader("Notify"))
End While
End Sub
Public Sub Reboot(ByVal State As Object)
Code....
strCounter += 1
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|