hashtable question

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
 
G

Guest

Starbuck,

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

Don't you just need to do:

clients.Remove (userName)

Kerry Moorman
 
M

Michel van den Berg

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
 

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