Folks, what is the neatest coding way of converting an async WCF service
call into an Action<> callback? Here is a sample of "student" code that does
this crudely:

 

public void AddTest(int num1, int num2, Action<int> callback)

{

       proxy.AddTestCompleted += new
EventHandler<AddTestCompletedEventArgs>(Proxy_AddTestCompleted);

       proxy.AddTestAsync(num1, num2, callback);

}

 

private void Proxy_AddTestCompleted(object sender, AddTestCompletedEventArgs
e)

{

       Action<int> callback = (Action<int>)e.UserState;

       callback(e.Result);

}

 

This works, but this is in an app-lifetime class and the event hander keeps
getting added on each call, so I would now have to balance the += add
handler with a -= remove handler in the Completed method. This is ugly and
not thread safe.

 

How do others deal with this pattern in a nice neat way? I know that some
MVVM pattern frameworks do this and hide the complexity, but I'm not using
such a framework at the moment and I'm curious about what they do
internally. I've seen Jordan and Paul run demos with Action callbacks from
service calls, but I didn't see the underlying code. Can you guys point me
to some samples?

 

Greg

_______________________________________________
ozwpf mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf

Reply via email to