(this should work in SL2 as well)
All network calls in Silverlight are asynchronous. The proliferation of event handling functions this can cause just makes for really cluttered code. Using lambda expressions seems to make my code a bit cleaner. (You can also use regular anonymous delegates, but the lambdas involve less typing)
public void LoadPolicyDetail()
{
IvcDataServiceClient client = new IvcDataServiceClient();
client.GetPolicyDetailCompleted += (s, e) =>
{
if (e.Result != null)
{
_policyDetail = e.Result;
if (PolicyDetailLoaded != null)
PolicyDetailLoaded(this, new EventArgs());
}
else
{
if (PolicyDetailLoadError != null)
PolicyDetailLoadError(this, new EventArgs());
}
};
client.GetPolicyDetailAsync();
}
The event handler is right in-line with the loading function. The event args remain strongly typed, so you have access to everything you normally would with an additional function.
In the example above, PolicyDetailLoaded and PolicyDetailLoadError are events I raise from my ViewModel, and GetPolicyDetailCompleted is the async call-completed event on the WCF client proxy.