3
Reply

Program freezes

Andy Dowd

Andy Dowd

Sep 9 2010 12:02 PM
1.9k
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)