473,326 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Hashtables: readding a removed object

Hi,

I've got a hashtable that contains of list of remote network Player
objects. The unique key used is the Player's IP address as a string.

The problem I'm getting is when a Player disconnects I do a

_RemotePlayer.remove[ipKey];

However, if the Player joins the game again and I add a new Player
object with the same IP address being the key to the hashtable I get an
ArguementException.

It seems to me that when I remove the Player from the hashtable the key
is not removed as well. How do I remove the key from the table? Am I
able to do that? or do hashtables always keep a used key and I have to
do a .ContainsKey check on it before adding players to the table?
Thanks in Advance,
MS

Nov 22 '05 #1
1 1279
<mi**********@gmail.com> wrote:
I've got a hashtable that contains of list of remote network Player
objects. The unique key used is the Player's IP address as a string.

The problem I'm getting is when a Player disconnects I do a

_RemotePlayer.remove[ipKey];
I suspect that's not what you actually do, as that won't compile.
However, if the Player joins the game again and I add a new Player
object with the same IP address being the key to the hashtable I get an
ArguementException.

It seems to me that when I remove the Player from the hashtable the key
is not removed as well. How do I remove the key from the table? Am I
able to do that? or do hashtables always keep a used key and I have to
do a .ContainsKey check on it before adding players to the table?


If you were actaully managing to remove the player from the hashtable,
you wouldn't have a problem. I suspect it's the removal side of things
which is the problem.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2

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

Similar topics

3
by: Cengiz Dincoglu | last post by:
When I insert a long value as key and the object to a hashtable. it fails at about 600,000 data points. ht.add(long, long) We are developing a real time application that is required to keep...
1
by: midnightswan | last post by:
Hi, I've got a hashtable that contains of list of remote network Player objects. The unique key used is the Player's IP address as a string. The problem I'm getting is when a Player...
6
by: Michael Schollmeyer | last post by:
Hello, The following code writes the text string: Uri uri1 = new Uri("http://www.here.net/aplace?param=one"); Uri uri2 = new Uri("http://www.here.net/aplace?param=two"); int h1 =...
4
by: Michael Maercker | last post by:
hi! i'm wondering what the differences are between hashtables und dictionarybases; can both of them store several different types of objects, each accessible by a string key? currently i'm using a...
4
by: Anders Borum | last post by:
Hello! I'm am currently working on making a central cache component threadsafe, and was looking at the synchronized implementation of the Hashtable. I was wondering why you'd really want to...
1
by: Curtis | last post by:
Does anyone know the proper method to save information to embedded hashtables. I am trying to save parent/child information to hashtables but I am not getting the correct results I have made a...
6
by: Erick | last post by:
I've created a class called Procs and a collection class called Processes which uses a hastable object to store the Procs. Now i want to enumerate with the "For each" to extract all the Procs in...
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...
0
by: John Smith | last post by:
Hello people, I have a performance query regarding LINQ that I would like some opinions. Currently we have a business logic framework that is used in n-tier applications. We read data from a...
0
by: Jake McCool | last post by:
Hello people, I have a performance query regarding LINQ that I would like some opinions. Currently we have a business logic framework that is used in n-tier applications. We read data from a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.