The best way to avoid having questions closed is to start out with a good, answerable question with an easily defined scope. As it now stands, your question is fine, but it's been edited 3 times, and there have been 23 comments on the question and answer, many of which gave the impression that you didn't possess a sufficient degree of experience or level of understanding for us to assist. Things like misinterpreting a diagnostic/troubleshooting step as a suggested solution, for example. Add to that the fact that what ultimately ended up being the correct answer had to be edited into the answer as a response to one of your question edits, and you have what's actually a rather poor Q&A that was eventually salvaged into something useful, rather than a question that was good and topical to begin with.
Not asking a good question with sufficient information leads to situations where multiple answers are posted, based on incomplete information, the question is edited multiple times invalidating the existing answers, and a lot of time and effort is spent on a Q&A thread that's completely useless to any future visitors because it's so convoluted and twisted around by the time it's successfully answered, or more often, abandoned for being not worth the trouble.
It's also helpful to understand the standards of the community in which you're posting, as well as the way the site you're using works, which you very clearly don't. You'd tried to direct a question to a couple users by editing a question to them into your closed question, you're unfamiliar with the topicality rules of the site, don't appear to have read anything about the community (either how to ask a good question, or whom this community is composed of), and despite being a member on Stack Overflow for over 4 years, incorrectly identified a regular user as a moderator, didn't know the process for reopening a closed question and ostensibly were unaware of what to do when disagreeing with an actual moderator.
So there you have it - reading up on how to ask a better question and familiarizing yourself with the community are your best ways to "
prevent such events from occurring".