Question

Ok ... next question. I am using Silverlight 5 C# 2012 and have gotten to a point where I could use a little help. I am using the Domain Model to call methods to return information and I discovered that if I hit the same button more than once, the method call happens incrementally. One call for the first click, two calls for the second click, three call for the third, etc.

Please check out the simple code below and if you can provide any insight as to why this is happening, I would greatly appreciate it.

In the Service Layer:

Interface:

[OperationContract]
string GetEnteredString(string strText);

Class:

public string GetEnteredString(string strText)
{
    return "You entered: " + strText;
}

In the Silverlight Application:

private void btnGetText_Click(object sender, RoutedEventArgs e)
{
    service.GetEnteredStringCompleted += new EventHandler<CARE_WCF.GetEnteredStringCompletedEventArgs>(service_GetEnteredStringCompleted);
    service.GetEnteredStringAsync(txtTester.Text);
}

private void service_GetEnteredStringCompleted(object sender, CARE_WCF.GetEnteredStringCompletedEventArgs e)
{
    MessageBox.Show(e.Result.ToString());       
}

This seems pretty darn straight forward at first glance, but the call to the GetEnteredString method just keeps stacking on top of itself. I think it's because of the += in the Click event but I could be wrong.

Thank you in advance for any insight! I really appreciate it. Eric

Was it helpful?

Solution

You have to unsubscribe from the event in Completed function like :

service.GetEnteredStringCompleted -= service_GetEnteredStringCompleted;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top