It's expected behavior.
You have assigned the event handler 3 times, right? Then when you click on the button it will run 3 times, no matter what you do inside the event handler.
So it basically does this for 3 times:
- Show Hi
- Remove event handler 10 times
- Show Bye
After completing these 3 rounds, now if you click on the button again, it doesn't run the event handler, because you have removed the event handlers. Well, as a side-note, you don't need to remove the event handler 10 times; 1 time will be enough.
You should not assign the event handler more than once. If you assigned, then you cannot disable it inside the event handler itself, it's too late.