The heart is made bunch of a cells that have chemicals/ions going in and out of it. These ions have charges eg Sodium is a single charge (Na+), Potassium is a single charge (K+), and Calcium has two charges to it (Ca++ or Ca2+). Most of the heart is "electrical" so a beat can originate from there, but there are electrical highways of the heart that are even more electrical than the rest of the heart.
Usually, the start of the of the electrical highway is in the top right of the heart called the "sinus nose". This is where beats usually originate. It is usualully the fastest to create electrical beats (depolarization "shock"/repolarization "recharging"). The speed of this is usually 60-80 bpm (beats per minute) at rest. Since it is the fast, it is usually the leader dictating when other slower parts of the heart depolarize/shock. When this parts fail, the next fastest part of the heart will take over. Usually the top part of the heart is fastest and it gets slower as you down towards the bottom of the heart. So if the top part of the heart fails, the sinus node, the next part is the middle part of the heart called the "AV node". This is usually taught to be 40-60 bpm (since the sinus node is faster, the sinus node usually shocks this before it shocks itself, but when the SA node fails, this will shock itself making the heart beat usually 40-60 bpm). If the AV nodes, the bottom part of the heart called the ventricles will shock itself at 20-40 bpm.
The top part of the heart has an important role with filling the bottom of the heart with blood. If the top part is not working, your body will pump less blood in a timely manner.
When we use an automated external defibrillator (AED), we are trying to treat irregular electrical activities of the heart "cardiac arrhythmia" or "dysrhythmia". The two arrhythmias it treat are "ventricular fibrillation" or "ventricular tachycardia".
Regardless of which of the two rhythms it is, the goal with shocking the patient is to make all my cells "shock" or "depolarize" at the same time. This way it allows the fastest one, the sinus node, to take over again, and allow the heart to beat slower and down the normal electrical highway of the heart to allow the top and bottom part of the heart to pump in a uniform/systematic manner that is effectivr rather than chaotic.
Ventricular tachycardia means the electrical beat that is shocking is starting at the bottom of the heart. This means that the top of the part is likely not working with the bottom. On top of that, if it is beating too fast, not only is the top not filling the bottom with blood, but it is beating to fast to even relax to allow blood into bottom part passively. Ventricular tachycardia can have a pulse, usually when slow enough, but not always. The AED is often built to calculate the heart rate so if it is slow, usually <150 bpm, it will not shock even if the patient is in ventricular tachycardia. This is one of the mechanisms to prevent shocking people with pulses although it doesn't physically detect pulses. Like others said, when it does shock, it shocks right then and there usually. Some people argue it sould be better to "synchronize" shock (eg tell when a ventricular beat is about to happen) to optimize the best time shocking, but we are still trained to shock whenever when the patient has no appreciable pulse.
In ventricular fibrillation, the heart has electrical activity all over the place causing it to squeeze in a non uniform way that is not effective at all to pump blood. The electrical beats are all working on their own rather than together. Again, shocking is causing them all to shock/depolarize at the same time and hopefully give the sinus node a chance to lead again by it shocking itself before all the other ones fight to be leaders again.
There are many other rhythms that are viable with life, so they do not require shocking since the problem is not an arrhythmia when someone is in cardiac arrest, and focus should turn to other cause (eg someone could have normal cardiac rhythm, the AED won't shock, but the person has no blood because they are bleeding out, so the focus is to get them to surgery or give them fluids/blood if the patient isn't determined dead on scene).
Hopefully that explains it in less technical terms for you and makes sense. If you need clarification, don't be afraid to ask.