A foreigner can gain permanent residence in Thailand. You can do so after three straight years of a non-immigrant visa.
* Retirement visa
* Work visa
* Marriage visa
If you skipped a year you have to start again.
Then you must have ONE of these:
* Investment (3-10 Million THB)
* Working or Business in Thailand
* Support a family (wife, child under 20, etc)
* Expert or Academic
* Others as determined by Immigration
Most people reading this will probably be working, have a business or support a family.
There is an annual quota of 100 persons per country! So it could take quite a number of years to get it depending on the country you come from.
The residence permit never expires. But you do need a re-entry permit to travel in and out of Thailand.
And you can apply for citizenship after 10 years of being a permanent resident!