Spot The Mistake 1
August 21, 2010 – 18:30This one had me puzzled for about an hour, I shall endeavour to post the answer in the comments in short order.
foreach (var id in CharacterIdentities) { QueryMethodAsync( APIMethods.CharacterSkillInTraining, m_userId, m_apiKey, id.CharacterID, (x) => OnSkillInTrainingUpdated(x, id)); }
4 Responses to “Spot The Mistake 1”
Not knowing the calls or object model, I’m going to guess that the id.CharacterId is incorrect and should just be id because you got the id from Character Identities?
By Kirith Kodachi on Aug 22, 2010
As pointed out by Kirith Kodachi the bug is obscured somewhat by the object model I am working with, however you would get the same bug from the following code:
The result would be DoSomething would be called with the parameter == 4, five times because the variable existed within it’s initial scope, then kept in scope by the Lambda expression.
In the end the resolution was to use the following code:
Which results in the DoSomething being called five times, with the number 0..4.
By Richard Slater on Aug 23, 2010
Ah right, I’ve run into that before. Resharper usually reminds me not to do that
By Kirith Kodachi on Aug 24, 2010