multithreading - C# exception: Key is not present in the dictionary -


I have a little problem Sometimes, when I try to call the following code, the message An exception with the message "Exception key does not exist" throws.

  Personal dictionary & lt; IPAddress, ARPHostEntry & gt; DIPHostTable; Private dictionary & lt; MACAddress, ARPHostEntry & gt; DMACHostTable; Public Hostet () {dIPHostTable = New Dictionary & lt; IPAddress, ARPHostEntry & gt; (); DMACHostTable = New Dictionary & lt; MACAddress, ARPHostEntry & gt; (); } Add Public Zero Hot (ARP Host Entry Error) {Lock (DAMextstable) {if (DAMexttable.contentkey (ARFentry.mac)) {DAMextstable. Raviv (ARFentry.mac); } DMACHostTable.Add (arphEntry.MAC, arphEntry); } Lock (DIP Hosttable) {if (DIP HostTable.Connentki (ARFentry.IP)) {DIP Hosttable.rive (ARFentry.IP); } DIPHostTable.Add (arphEntry.IP, arphEntry); The class ARPHostEntry is a simple calss in which an IP address and an associated MAC address where both fires in this class are only readable, the program is multi-threaded, but every time I I use them to lock the dictionaries in this class. 

I'm helpless.

Edit

For clarification, the accepted answer is correct. The exception was generated due to cross-thread access to my dictionaries

Remove the exception to this method Should not be thrown, it should be wrong if the key is not found (see). Instead of deleting and adding, why do not you try to update the value of the key?


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -