Reading Key Value from Collection in VB.NET

S

Steven Thomas

I have a VB.NET application that manages multiple theads.

I have created a collection to handle the threads

Dim colThreads As New Collection()

then when I create a new thread I add it to the collection
'ADD A HANDLER TO CAPTURE DATA BACK FROM THE THREAD
AddHandler cAccessFunc.ThreadDone, AddressOf RptMSAThreadDone
Dim othread1 As New Thread(AddressOf cAccessFunc.CAccessSnapShot)
cFunctions.WriteEventLog("Add thread to collection : " &
CStr(arThreadCnts(1, c)))
' SET THE PROPERTIES OF THE CLASS AND START NEW THREAD
othread1.Name = CStr(arThreadCnts(1, c))
colThreads.Add(othread1, RTrim(CStr(arThreadCnts(1, c))))
.......

The value in arThreadCnts(1, c) is a unique string
When I try to read the from the collection to check on a thread I and
doing this:

cFunctions.WriteEventLog("ThreadName: " & CStr(pThreadName) & " col
thread name:" & colThreads.Item(CStr(pThreadName)).tostring)
If colThreads.Item(d).ToString = RTrim(CStr(pThreadName)) Then
Dim aThread As Thread = colThreads.Item(CStr(pThreadName))
aThreadState = aThread.ThreadState.ToString
cFunctions.WriteEventLog(Thread state: " & CStr(aThreadState))
If aThread.ThreadState = ThreadState.Running Then
aThread.Abort()
colThreads.Remove(RTrim(CStr(pThreadName)))
cFunctions.WriteEventLog(Thread removed: " &
CStr(pThreadName))
End If
End If


When I view the event log I get col thread
name:System.Threading.Thread

Does anyone see what I am doing wrong? Why I do not get a Key set for
each item I am adding to the colletion?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top