I am making an asynchronous
call to wcf service methods and generated a Completed
event on Button
click:
private void OnSearchProductClick(object sender, RoutedEventArgs e)
{
service.GetProductsCompleted += new EventHandler<GetProductsCompletedEventArgs>(webService_GetProductsCompleted);
ProductType productType = (ProductType)cboProductType.SelectedItem;
_productTypeID = productType.ProductTypeID;
service.GetProductsAsync(txtName.Text, txtCode.Text, _productTypeID);
}
Problem is, the webService_GetProductsCompleted
event gets called multiple times. When click
the Button for first time it gets called once, when I click second time gets called twice when click third time gets called thrice and so on. This is a very unusual behavior. Why is it happening and how can I resolve it?
Here is the webService_GetProductsCompleted
event:
public void webService_GetProductsCompleted(object sender, CatalogueServiceReference.GetProductsCompletedEventArgs e)
{
if (e.Result.Count != 0)
{
PagedCollectionView pagingCollection = new PagedCollectionView(e.Result);
pgrProductGrids.Source = pagingCollection;
grdProductGrid.ItemsSource = pagingCollection;
pgrProductGrids.Visibility = Visibility.Visible;
}
}