Let's jump straight into a few examples!
1. When you're walking your dog and you ask him to sit but he doesn't listen.
If sitting is something your dog normally does on walks with little difficulty, if you're finding that they're struggling to do so all of a sudden, you should first take a moment to wonder if there are any external factors (such as noises, smells, people, dogs, or cars, etc) that are either distracting or concerning to your dog.
If so, then the best thing you can do is avoid repeating the verbal command/cue and instead help your dog walk away in a fun, light way until they feel more at ease and you can reconnect with one another, before trying again.
2. When you're in a classroom (for dog training) and your dog isn't listening.
Break down the lesson you're trying to work on, with your dog that you're finding they're struggling with. Your trainer can help you with this, but the most important thing when it comes to your dog not listening is how you react. Practice making things easier for your dog by re-trying the lessons/commands you're working on with your dog, in a way that is more doable for you both.
If your dog isn't listening, chances are they're either having an off day, they're tired, overstimulated, or feeling too distracted. Ge what you can during class but be sure to practice again, at home.
3. When you're at the dog park/at a social setting and he doesn't listen.
From experience, in social settings, most pet parents tend to speak and expect their dogs to listen when they're doing something they're not happy with. If this is a habit that has been forming over time, it might be wisest to revisit these environments as a whole.
If your dog isn't successfully listening to you here and there, the best thing for you to do is to help them walk away (preferably done using a leash) and try speaking to them once again when they've reconnected with you and given you more of their attention. If they're struggling to focus on your voice in a social setting, it could be due to similarly challenging elements as the first example.
To conclude, the common denominator among all examples above is that before expecting your dog to listen to you, you will want to practice even more listening on your part. One thing is for sure: dogs aren't listening on purpose or because they don't want to. They're simply reacting to their environment around them and if you pay close attention to it and them, you will be even more in tune with your dog which will let your dog know that you listen to them as well!