I have a TreeView with 1000 items. When I select an item, the TreeView fires an event so I can update something in my GUI. The event handler is non recursive and has no loops, but it does take a little bit of time to complete, maybe 100ms.
If I select the top item and use the down arrow to scroll through items slowly, everything works fine, but if I hold down the arrow key, the event fires too quickly and I get a stackoverflow exception.
I thought about putting a timer in the TreeView so the SelectionChanged event can only fire every 100ms or so, but that seems very hackish. Any ideas for fixing this?
I’ve seen stuff like this happen on winforms as well. One way that I have seen people implement is to have a delayed event handler. Such that it fires only after the said item has been selected for a specified time period.
So the way that works is you have an event handler that executes a timer. The timer gets reset whenever the selectionchanged event is fired. Your timer would be maybe 500ms so if the selected value is still selected after 500ms it will then fire your actual event code you need handled.
Not saying this is the best way just a way I have seen it handled in windows forms.