Been doing quite a bit of silverlight programming lately and loving it but of course silverlight is async so i am forced to setup an event handler to call when the async is complete. This works great of course but i am just getting lots of code… basically 2 methods for everycall that i require to a wcf service. I recently discovered the following
client.LoadClientsCompleted += (sender, e) =>
{
// My Code
};
client.LoadClientsAsync(clientID);
It seems to work, its using lambdas rather than a physically method. I understand that this doesn’t change the working of the technology and its still async. but it seems to tidy up my code quite a lot.
I would love to hear any comments on weather i should be using this, are there any PROS and CONS using either?
As i say point the event directly at a new method works great as well but technically i have 2 methods for every call i make … The code is growing 🙂
Using the lambda way i at least keep my callback event within my current method although it only fires when complete. It seems to make things easier BUT are there any problems with this method?
One big pro is that lambdas can capture the value of variables from their surroundings: