Well, locking a dictionary seems to be not that clear.
Thats how i do it.
Thats how public sources do it
Thats how others do it
Version 1: Im getting "Collection Modified" Errors
Version 2: Getting no Errors but the loop lasts sgnificantly longer
Version 3: Getting no Errors but sometimes the loop runs 2 times at once.
Sooo... how do you lock a dict?
PHP Code:
Monitor.Enter(AllMobs);
{
foreach (KeyValuePair<uint, Mob> kvp in AllMobs)
{
Mob m = kvp.Value;
m.GetTarget();
}
}
Monitor.Exit(AllMobs);
Thats how public sources do it
PHP Code:
lock(AllMobs)
{
foreach (KeyValuePair<uint, Mob> kvp in AllMobs)
{
Mob m = kvp.Value;
m.GetTarget();
}
}
PHP Code:
private readonly object SyncLock = new object;
Monitor.Enter(SyncLock);
{
foreach (KeyValuePair<uint, Mob> kvp in AllMobs)
{
Mob m = kvp.Value;
m.GetTarget();
}
}
Monitor.Exit(SyncLock);
Version 2: Getting no Errors but the loop lasts sgnificantly longer
Version 3: Getting no Errors but sometimes the loop runs 2 times at once.
Sooo... how do you lock a dict?