I've not read your project file but I think you likely lost the IExternalCommand context as soon as you showed a modeless dialogue i.e. code continued and ended after .show was called.
If you want to interact with Revit this way then you probably should make use of the IExternalEvent otherwise you need to use a modal dialogue.
Typical external event workflow would be as follows:
Step 1 show window as part of IExternalCommand
Button is clicked
Step 2 as part of button click raise external event and close window.
Revit responds with new context within external event handler
Step 3 handle external event by picking objects and then show the same window again.
Should state that closing and opening a window is not a requirement but if you want to direct the users attention away from the window then this could be done. In reality modeless dialogues are meant to just hang around until you choose to close them.
You have to keep a record of if the window is already visible. Generally in the past I would create a static variable to contain the window outside of the window class and within the window closed event set it to null. Then when command is run check if variable is null if so then instantiate a new instance of it and show, otherwise exit the IExternalCommand.
People are still using modeless forms since it is convenient to their knowledge base but in reality implementing IDockablePaneProvider is a better solution for modeless interaction. The state of Revit is inherent e.g. there has to be an active UI doc to use a button on a pane therefore you don't have to check this or handle document closing events to help monitor when there isn't one.