473,473 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

hashtable question

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
--

Kevin Martin
Motor Trade Technologies
Nov 23 '05 #1
3 978
Starbuck,

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

Don't you just need to do:

clients.Remove (userName)

Kerry Moorman
"Starbuck" wrote:
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
--

Kevin Martin
Motor Trade Technologies

Nov 23 '05 #2
Hi Kerry

You are right, as simple as that. Many thanks

"Kerry Moorman" <Ke**********@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
Starbuck,

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

Don't you just need to do:

clients.Remove (userName)

Kerry Moorman
"Starbuck" wrote:
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
--

Kevin Martin
Motor Trade Technologies

Nov 23 '05 #3
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
"Starbuck" <St******@tisconi.com> schreef in bericht
news:dd*****************@newsfe6-gui.ntli.net...
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
--

Kevin Martin
Motor Trade Technologies

Nov 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: francois | last post by:
Hi, I have a webservice that I am using and I would like it to return an XML serialized version of an object. the class of the object is defined serializable as the following: public...
5
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would...
5
by: Cyrus | last post by:
I have a question regarding synchronization across multiple threads for a Hashtable. Currently I have a Threadpool that is creating worker threads based on requests to read/write to a hashtable....
33
by: Ken | last post by:
I have a C# Program where multiple threads will operate on a same Hashtable. This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable) method, so no further Lock statements are...
5
by: ad | last post by:
I have a hashtable name myHash. sKey is a string, I use myHash to retrieve the value of that key. But is sKey is not in the myHash.Keys, it raise an Exception. I want to dertiminate if sKey in...
2
by: Ali | last post by:
I am binding a hashTable to a dropDownList to pick a State (key: like New York) and sends the state designation (value: NY) to a filtering procedure. I have entered the states in the hashTable in...
8
by: Robin Tucker | last post by:
When I create a hashtable hashing on Object-->Item, can I mix "string" and "integer" as the key types? I have a single thumbnail cache for a database with (hashed on key) and a file view (hashed...
4
by: Macca | last post by:
Hi, I am using a hashtable as a cache. I am only allowed for the cache to take up a certain amount of memory. I think I can state how large I want the hashtable to be on creation. What I...
2
by: PAzevedo | last post by:
I have this Hashtable of Hashtables, and I'm accessing this object from multiple threads, now the Hashtable object is thread safe for reading, but not for writing, so I lock the object every time I...
2
by: archana | last post by:
Hi all, I am having one confusion regarding hashtable. I am having function in which i am passing hashtable as reference. In function i am creating one hashtable which is local to that...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.