hashtable question

  • Thread starter Thread starter Starbuck
  • Start date Start date
S

Starbuck

Hi

The procedure below is called when a user disconnects and the control
program trys to remove them from the hashtable
There are no errors but the .Remove option does not remove the entry from
the table, any ideas please.
Private clients As New Hashtable



Private Sub DisconnectUser(ByVal userName As String, ByVal sender As
UserConnection)
Dim client As UserConnection
Dim entry As DictionaryEntry
Try
UpdateOutStatus(userName & " has disconnected.")
For Each entry In clients
client = CType(entry.Value, UserConnection) '
If client.Name.ToString = userName Then
clients.Remove(entry)
End If
Next
reBuildConList()
Catch ex As Exception
ErrorBox(ex.Message)
End Try
End Sub
 
Starbuck,

The hashtable's Remove method takes a key as the argument.

Don't you just need to do:

clients.Remove (userName)

Kerry Moorman
 
Hi Starbuck,

by looking at the docs, it seems that ...

"If the Hashtable does not contain an element with the specified key,
the Hashtable remains unchanged. No exception is thrown."

So I expect that, entry is not the same object as the object being asked for
in the hashtable.remove() function. Please check it when debugging.
I expect you have to use clients.Remove(entry.Key) but I am not sure: give
it a try and let us know.

Michel van den Berg
 
Back
Top