Completed event problem

May 17, 2011 at 9:49 AM


In this library, the begin/endexecute methods with callback handlers are replaced with begin/endexecute events.
No problem there, cleaner syntax IMO, but if you subscribe to the completed event you should never forget to unsubscribe because if you work with multiple executes, all methods that subscribed to the completed event will fire.
An even bigger problem is when you have to perform multiple executes at the same time (which is my scenario..). With this scenario, you can not know what execute will return first, so the unsubscribe method won't work here.
Is there any solution for this?

Thanks in advance,

Arne Deruwe

May 23, 2011 at 7:22 PM


Please download the latest version from the Source Code tab and build it.  It changes the ASyncState object to be something more useful.

It now encapsulates the service, id, and a data object in a class called SoapAsyncState.   That way you can use the result to verify it was the request you sent. So that if you call something like:

BeginCreate(myContact,contactCreated,new SoapAsyncState("ContactCreation",someData));

You can use it in the contactCreated method:

private void contactCreated(IAsyncResult ar)
    var state = ar.ASyncState as SoapAsyncState;
    if (state==null state.Id!="ContactCreation") return;


That should allow you to handle the multiple requests and the better handling of your async calls.

Oct 5, 2011 at 2:14 PM


Sorry for the late reply, my CRM project was done and I totally forgot this thread.
Now I'm working on a new CRM project and this change is exactly what I needed, thanks and keep up the good work!