// // Background worker thread entry point. This is NOT the UI (primary) thread context. // //#if WINDOWS_PHONE //public void bw_DoWork(object sender, DoWorkEventArgs e) //#endif private void prvRunTest() { int error = 0; int retValue = 0; // 0 for no errors else error code // BackgroundWorker worker = sender as BackgroundWorker; //SpeechSynthesizer s = new SpeechSynthesizer(); //Random myRandomGenerator = new Random(); int rate = pTest.GetDelayBetweenPairs(); int numTests = pTest.GetNumTests(); int[] dataTable = null; int testLength = 0; dataTable = pTest.GetTestTable(out testLength); //Int32 randomInt; //Int32[,] memory = new Int32[pTest.numTests, testLength[0] ]; Int32 digit = 0; Int32 newDigit = 0; Int32 expectedSum = 0; for (int i = 0; i < numTests; i++) { // if ((true == worker.CancellationPending )) // { // e.Cancel = true; // break; // } String speakString = "Starting test number " + i + " at " + rate + " milliseconds in 5 seconds"; // s.Speak(speakString); // MessageBox.Show(speakString); // uncomment for DEBUG // Thread.Sleep(5000); for (int j = 0; j < testLength; j++) { //randomInt = myRandomGenerator.Next(11); //memory[i, j] = randomInt; // Check if this the digit or the sum from the array if ((j % 2) != 0) { // Odd index means this is the sum expectedSum = dataTable[j]; newDigit = expectedSum - digit; if (newDigit <= 0) // check for table data error(s) { // s.Speak("Error in built in table data, sum minus previous digit is negative"); // Thread.Sleep(3000); speakString = "Error in data, sum of " + expectedSum + " minus the previous digit " + digit + " is negative " + newDigit; // s.Speak(speakString); #if WIN_PC_PLATFORM || WINDOWS_PHONE MessageBox.Show(speakString); #endif error = 1; Thread.Sleep(3000); break; } digit = newDigit; } else { digit = dataTable[j]; } // s.Speak(i.ToString()); // s.Speak(randomInt.ToString()); // s.Speak(digit.ToString()); PlayDigitSound(digit); // about 2 Seconds // Check for user cancelling test if (true == pTest.GetTestDoneFlag()) { numTests = 0; // don't do any more tests break; } Thread.Sleep(rate); // 2 or 3 Seconds // Check for user cancelling test if (true == pTest.GetTestDoneFlag()) { numTests = 0; // don't do any more tests break; } } if (error != 0) { break; } // calling code now sets the rate // rate += pTest.rateIncrement; // if ((worker.CancellationPending == true)) // { // e.Cancel = true; // break; // } } if (error != 0) { retValue = error; } //s.Speak("Hello. My name is John Byrne. I was born a poor white child."); // Print out the answers // // This was important when using RANDOM numbers but not important when using fixed internal table values // because the spreadsheets have the same table values // // COMMENTED OUT // /* * Console.WriteLine("The answers are: "); * for (int i = 0; i < pTest.numTests; i++) * { * Console.WriteLine("Test number: {0}", i); * StringBuilder testNumbersString = new StringBuilder(); * testNumbersString.Append("Test Number: " + i.ToString() + "\n"); * for (int j = 0; j < pTest.testLength; j++) * { * //testNumbersString.Append(memory[i,j].ToString() + " "); * //System.Console.Write(memory[i, j] + " "); * } * MessageBox.Show(testNumbersString.ToString()); * Console.WriteLine(); * * for (int j = 1; j < pTest.testLength; j++) * { * //Console.Write((memory[i, j - 1] + memory[i, j]) + " "); * } * Console.WriteLine(); * Console.WriteLine(); * } */ pTest.SetTestDoneFlag(true); // done backThread = null; // release reference to background thread }
// // Background worker thread entry point. This is NOT the UI (primary) thread context. // private void prvRunTest() { //SpeechSynthesizer s = new SpeechSynthesizer(); //Random myRandomGenerator = new Random(); int startingRate = pTest.GetDelayBetweenPairs(); int rate = startingRate; int[] dataTable = null; int testLength = 0; dataTable = pTest.GetTestTable(out testLength); int numTests = pTest.GetNumTests(); if (null == sound1) { prvLoadSounds(); } //Int32 randomInt; //Int32[,] memory = new Int32[pTest.numTests, testLength[0] ]; Int32 digit = 0; Int32 newDigit = 0; Int32 expectedSum = 0; int error = 0; for (int i = 0; i < numTests; i++) { String speakString = "Starting test number " + i + " at " + rate + " milliseconds in 5 seconds"; //s.Speak(speakString); // MessageBox.Show(speakString); // uncomment for DEBUG //Thread.Sleep(5000); for (int j = 0; j < testLength; j++) { //randomInt = myRandomGenerator.Next(11); // NOTE: This would sometimes generate 0 and 10 which are invalid according to PDF //memory[i, j] = randomInt; // Check if this is the digit or the sum from the array if ((j % 2) != 0) { // This is the sum expectedSum = dataTable[j]; newDigit = expectedSum - digit; if (newDigit <= 0) { // s.Speak("Error in built in table data, sum minus previous digit is negative"); //Thread.Sleep(3000); speakString = "Error in data, sum of " + expectedSum + " minus the previous digit " + digit + " is negative " + newDigit; //s.Speak(speakString); error = 1; Thread.Sleep(3000); break; } digit = newDigit; } else { digit = dataTable[j]; } // s.Speak(i.ToString()); // s.Speak(randomInt.ToString()); //s.Speak(digit.ToString()); PlayDigitSound(digit); Thread.Sleep(rate); } if (error != 0) { break; } // rate no longer changes here // rate += pTest.rateIncrement; } //s.Speak("Hello. My name is John Byrne. I was born a poor white child."); // Print out the answers // // This was important when using RANDOM numbers but not important when using fixed internal table values // because the spreadsheets have the same table values // // COMMENTED OUT // /* * Console.WriteLine("The answers are: "); * for (int i = 0; i < pTest.numTests; i++) * { * Console.WriteLine("Test number: {0}", i); * StringBuilder testNumbersString = new StringBuilder(); * testNumbersString.Append("Test Number: " + i.ToString() + "\n"); * for (int j = 0; j < pTest.testLength; j++) * { * //testNumbersString.Append(memory[i,j].ToString() + " "); * //System.Console.Write(memory[i, j] + " "); * } * MessageBox.Show(testNumbersString.ToString()); * Console.WriteLine(); * * for (int j = 1; j < pTest.testLength; j++) * { * //Console.Write((memory[i, j - 1] + memory[i, j]) + " "); * } * Console.WriteLine(); * Console.WriteLine(); * } * * // call the windowing system to reset the button * // Can't do this because it's a different thread calling us * // completedFunction(); */ pTest.SetTestDoneFlag(true); // done backThread = null; // release reference to background thread }