Switch CreateThread to _beginthreadex, use GC version when GC is enabled. Closes #669