Skip to main content

Microsoft Silverlight

Answered Question Autocomplete causing webservice to loop?RSS Feed

(0)

moonlit_valley
moonlit_...

Member

Member

1 points

13 Posts

Autocomplete causing webservice to loop?

Hi all, long time reader, first time poster, I have a bug in my code that I just can't pinpoint. I hope you can help. It's a silverlight Virtual Earth project.

I have an datagrid templated autocomplete that is retrieving it's data via a silverlight webservice. When an item is selected from the drop down list, the SelectionChanged event triggers another webservice that retrieves polygons relevant to the autocomplete selection made, and these are drawn on the map. The problem is that the routine that draws the polygon in question, gets called too many times. If I make a selection from the autocomplete, the routine is called once, if I make another selection, the routine gets called twice. If I make another selection, it gets called three times and so on. This in effect draws the same polygon several times on top of itself, taking longer each time and negating the required opacity (the polygon gets darker and darker eachtime).

There are no loops in my code. When debugging the whole routine is called, i.e. the debugger runs from line 1 (below) to line 5, and then returns straight to line 1. Any thoughts on this before I post the code in detail?

1. Private Sub svcGetPoly_ServiceHasNowCompleted2(ByVal sender As Object, ByVal e As GetPolyFromDBCompletedEventArgs)

2. If e.Error Is Nothing Then

3. DrawPoly...

4. End If

5. End Sub

Many thanks

Drew

Ken Tucker
Ken Tucker

All-Star

All-Star

16276 points

2,479 Posts

Answered Question

Re: Autocomplete causing webservice to loop?

 The thing that comes to mind is you are adding a new event handler without removing the old one first.  First time it runs 1 handler so the event runs once.  The second time there are 2 handlers so the event runs twice. etc

jay nanavati
jay nana...

Contributor

Contributor

3388 points

624 Posts

Re: Autocomplete causing webservice to loop?

can you share code for selectionchanged event?

Jay K Nanavaty
www.technologyopinion.com
Mark as answer if it helps. It will also help others...

moonlit_valley
moonlit_...

Member

Member

1 points

13 Posts

Re: Re: Autocomplete causing webservice to loop?

Ken, you're a genius. Thanks for your help. 

 Jay, no problem

Private Sub MyAutoComplete_SelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles MyAutoComplete.SelectionChanged

Dim MyAutocompleteResult as String

MuAutocompleteResult = MyAutoComplete.SelectedItem

'Trigger the call to the web service

AddHandler ServiceNameClient.ServiceNameCompleted, AddressOf TheRoutineYouWantToCallWhenCompleted

ServiceNameClient.ServiceNameAsync(MyAutoCompleteResult)

End Sub

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities