Um.
Look at your code:
var result = CheckIfDivisible(p, q);
do
{
generatepnq();
} while (result == false);
Since
result
is a local variable and you never send it to the method, once it enters the loop, it will never exit. To make matters worse, that code is inside the generatepnq method, so it will eventually run out of stack while trying to recursively call itself an infinite number of times...
Please, use the debugger - look at exactly what is going on, because it would have taken you seconds to find out that the infinite loop is not where you think it is!