Facing some problem calling methods in Silverlight.
Here’s the scenario :–
My service agent contains the method which is calling a method in WCF service. The way i am calling is this :
public void GetMethod(EventHandler<GetMethodCompletedEventArgs> callback)
{
_Proxy.GetMethodCompleted += callback;
_Proxy.GetMethodAsync();
}
I am calling this method in the View Model like this
private void SomeMethod()
{
ServiceAgent.GetMethod(inputVariable, new EventHandler<GetMethodCompletedEventArgs>(OnGetMethod_Completed));
}
void OnGetMethod_Completed(GetMethodCompletedEventArgs e)
{
int result = e.Result;
}
I have attached the method in the view model to a button in the UI.
Now the problem is, if i press the button first time everything works fine, if i press it twice the OnGetMethod_Completed() gets executed 2 time for one button click(i.e. 2nd button click), when i press it the third time it get executed 3 times and so on…
I really don’t get it why this is happening, if anybody does then please help me out.
Thanks in advance
you need to unregister from the completed event on your OnGetMethod_Completed