Ortho evaluation. Actual knee dislocation is often the result of significant trauma and is incapacitating. Based on that it sounds as though you are referring to recurrent patellar (kneecap) dislocation. The unstable knee cap will often relocate on its own but sometimes requires relocation by a physician. However recurrent dislocation can be debilitating and thus warrants evaluation by an orthopedic surgeon.
Prevention!! It sounds like your patella (knee cap) may be loose. If it frequently slides, you would likely benefit from a brace with a cut out for the knee cap to help it track evenly. A good quadriceps and hamstring balance and strengthening program would also be useful. It is important to prevent this from recurring, as it can damage the cartilage under the patella.