Andy Dowd

Andy Dowd

  • NA
  • 1
  • 2.2k

Program freezes

Sep 9 2010 12:02 PM
Hi, can someone help me, I don't know what to do to stop my program from freezing when there are no more results.  Here is the snippet of code
  while (codeCollection.Count < numberOfCodes)

        {       
            

            String currentCode = generateCode();

            CodeVerification cv = new CodeVerification();

           
            if ((cv.checkWords(currentCode) == -1) && (cv.checkSameChars(currentCode) == -1) && (cv.checkCodeMix(currentCode, percentLet, percentNum) == -1))
            
		{
                if (codeCollection.Add(currentCode))

                {
                    filePrint.WriteLine(currentCode);
                }
            }
            }

This is part of a program to generate random numbers (codes) and when there are more codes requested than are possible (hashset doesn't take duplicates) the program freezes, I tried to put in a try catch block but it didn't work, any suggestions??
Thanks

Answers (3)