Try this Greg:
EventHandler<T> handler = null;
handler = (s, e) =>
{
client.GetFooCompleted -= handler;
Trace("GetFoo result is {0}", e.Result);
};
client.GetFooCompleted += handler;
client.GetFooAsync(rowId);
You'll have to put in the right type for `EventHandler<T>`.
Let me know if that works.
Cheers.
James.
From: [email protected] [mailto:[email protected]] On
Behalf Of Greg Keogh
Sent: Saturday, 2 March 2013 15:24
To: ozDotNet
Subject: Async coding pattern
Folks, I have some skeleton code like this in a Silverlight app:
client.GetFooCompleted += (s, e) =>
{
Trace("GetFoo result is {0}", e.Result);
};
client.GetFooAsync(rowId);
This works fine, but then I noticed that the completion handler code keeps
getting added on every call and the completion code runs 1, 2, 3, 4, etc times.
Is there an elegant way of rejigging this code to get the correct
one-call-one-completion behaviour.
Greg