Changeset 1221


Ignore:
Timestamp:
Feb 28, 2010, 5:22:11 PM (12 years ago)
Author:
Matthäus Wander
Message:

fixed enumeration while changed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/PeerToPeerPublisher/SubscribersManagement.cs

    r1220 r1221  
    8080        public bool Update(PeerId subscriberId)
    8181        {
    82             this.dateTimeNow = DateTime.Now;
    83             if (this.checkList.ContainsKey(subscriberId))
    84             {
    85                 this.checkList[subscriberId] = this.dateTimeNow;
    86                 // remove subscriber from this list, because it's updated now and hence alive!
    87                 if (this.secondChanceList.Contains(subscriberId))
    88                     this.secondChanceList.Remove(subscriberId);
    89                 return true;
     82            lock (this.checkList)
     83            {
     84                this.dateTimeNow = DateTime.Now;
     85                if (this.checkList.ContainsKey(subscriberId))
     86                {
     87                    this.checkList[subscriberId] = this.dateTimeNow;
     88                    // remove subscriber from this list, because it's updated now and hence alive!
     89                    if (this.secondChanceList.Contains(subscriberId))
     90                        this.secondChanceList.Remove(subscriberId);
     91                    return true;
     92                }
    9093            }
    9194            return false;
     
    130133            {
    131134                // added try/catch because checkList could be changed while iterating on it = boom!
    132                 try
    133                 {
     135                // wander 20100228: should not happen anymore since Update() locks now --> commented out
     136                //try
     137                //{
    134138                    foreach (KeyValuePair<PeerId, DateTime> entry in this.checkList)
    135139                    {
     
    146150                        }
    147151                    }
    148                 }
    149                 catch (Exception ex)
    150                 {
    151                     // don't handle this case, because outdated Peers will be added to the 2ndChanceList
    152                     // or will be removed the next time
    153                 }
     152                //}
     153                //catch (Exception ex)
     154                //{
     155                //    // don't handle this case, because outdated Peers will be added to the 2ndChanceList
     156                //    // or will be removed the next time
     157                //}
    154158            } //end lock(this.checkList)
    155159
Note: See TracChangeset for help on using the changeset viewer.