I struggle with this as well, though in the other direction: I really try to avoid imposing myself on others in my office to ask questions in person. I do think that I would be described as too cautious in this, so please keep that in mind when reading my answer. There is also a personal element which you can only figure out by trial and error-- some people simply dislike one mode of communication or another, regardless of situation.
When I'm trying to decide whether or not, and how, to approach someone with a work question in my office, I essentially run through a list of considerations which I break into two rough categories: a meta level (relating to how often I ask questions and how I generally go about doing so) and a specific-instance level (based on the details of a particular task and any questions associated with it).
1. How often do I ask questions of the specific person I would need to ask this time?
If I ask a given person questions more frequently, I'm causing more interruptions and consuming more of their time. More questions leads me to lean more towards email (or any other asynchronous method) for questions, so that the person I'm asking can fit my requests into their own schedules and workload more smoothly.
2. How does the person I would be asking usually communicate?
Some people are all about direct, in-person communication, while others are more reserved. If someone asks a lot of questions in person, it's a decent bet that they won't mind much if someone else asks a question of them that way. This can provide some guidance in situations where you haven't asked that person a question before, or you have asked but were not able to read that person's reaction very clearly.
3. Is there a pattern to the kinds of questions I find myself needing to ask?
There is nothing wrong with asking questions at work (I feel it's usually better to ask than not). But if you find yourself frequently asking questions on a particular topic, or in similar situations, it might be the case that, for whatever reason, that kind of information isn't so memorable to you. In those cases I like written questions (especially through email) because they are self-documenting. I can always refer back to the question I asked and the answer I got. A verbal interaction, even if I take notes, can be less clear in a later review.
4. How often does this person ask questions of me?
This one is pretty loose. There are a lot of professional arrangements where information is going to mostly flow one way: I might need information from our coding department, because I don't know much about medical coding in detail but still need to work with that data, but the coders don't generally need any information from me.
But among coworkers whose work overlaps frequently it can be good to have a frequent, informal pooling of knowledge and experience. If we chat about SQL coding practices we can both become better at it, and the less-formal situation of face-to-face interaction really promotes discussion and encourages more of it. Formality can be a barrier to that kind of interaction, and so I like to keep up the habit of personal interaction when I can.
1. How critical is my need for the information?
This can be a hard one to answer, but if I truly need the information immediately then asking in person is by far the best way to satisfy that need. If it seems like I often have urgent needs for information that suggests that some process could be improved (to avoid that kind of constant last-minute scrambling), or that the work environment is simply one that requires lots of ad hoc face-to-face interactions. But those are external to any given question you might need answered.
2. How much might I be expected to know the answer already, or figure it out myself?
This is definitely a lower priority than (Instance, 1), but if it's something that I might plausibly be expected to know or figure out then it's less reasonable to demand an immediate response. As above, if you need the information now then you need it now, but my weakness in some task or area isn't a reason to add burdens to my coworkers at my own convenience or need, and so I'm more likely to give my coworkers flexibility in how and when they respond.
3. How self-contained and well-defined is my question?
Some questions are very straightforward and specific, and can be answered completely without much trouble. For these questions I wouldn't worry about which way I ask. But some questions are fuzzier and require some amount of back-and-forth discussion to really address, and for those I overwhelmingly prefer real-time, face-to-face communication. I feel that it's less trouble than requiring both of us to monitor our inboxes or chat channels constantly.
4. How busy does the other person seem?
This can be hard to judge, but the busier a person is the less reasonable it is to demand that they drop what they are doing to address your need now. Even if you absolutely must have the information to continue your work, that's a problem for you, not your coworker (who has their own work to do).
5. What sort of relationship do I have with this person?
A close friend at work is probably going to be more interested in my needs than a vague acquaintance, and I feel more comfortable asking in person when there is more of a personal relationship there (otherwise it feels very self-centered and transactional to me). This is the type of person that I would expect to care about something like you being bad at task-switching-- that's a personal work issue, and outside of a supervisor or manager it's not other peoples' task to maximize your work efficiency.
On the other end of the spectrum there are some people that I find difficult to work with, interact with only if I absolutely have to, and with as much distance between us as possible. In cases like that it can also be valuable to communicate via email or chat so that there is a record of the interaction (but hopefully things aren't that bad!).
6. Does the person I need to ask seem to prefer one method over others?
You can only learn this through experience and observation, but if you are pretty sure that someone especially doesn't like to be approached in person and interrupted then it's better to avoid doing so (if you can).