0
System.Timers.Timer intervalTimer = new System.Timers.Timer(2000); // set the timer for 2 sec.
intervalTimer.Elapsed += new ElapsedEventHandler(intervalTimer_Elapsed);

private void doHearingTest(ArrayList TestSeq)
    {
        if (!initialTestCompleted && testPerFreqLeft == totalTestPerFreqForInit)
        {
            label1.Text += testFreqSet[(int)initTestSeq[currentFreqIndex]] + " , ";
            if (currentFreqIndex == numOfFreqTested - 1)
                label1.Text += " || ";
        }
        else if (initialTestCompleted && testPerFreqLeft == totalTestPerFreqForMalig)
        {
            label3.Text += testFreqSet[(int)maligTestSeq[currentFreqIndex]] + " , ";
            if (currentFreqIndex == numOfFreqTested - 1)
                label3.Text += " || ";
        }
        #endregion

        leftRightPan = (currentFreqIndex < numOfFreqTested) ? 10000 : -10000; //right = 10000
        int ear = (leftRightPan == 10000) ? 0 : 1;

        int freqIndex = (int)TestSeq[currentFreqIndex];


        int testVol = earFreqDBVolAdj[ear, freqIndex, currentTestVolIndex];


        noResponseTimer.Start();
        intervalTimer.Start();

        playTone(testFreqSet[freqIndex], testVol, leftRightPan, tonePlayTime);


        responseDetected = false;
        respondCounter = 0;
        testPerFreqLeft--;
    }

 private void intervalTimer_Elapsed(object sender, ElapsedEventArgs e)
    {

        intervalTimer.Stop();   
    }

I would like to have an interval of 2 seconds between the previous tone and next tone play. Any idea how this could this be done? Many thanks.

Hassan
  • 5,360
  • 2
  • 22
  • 35
PLS HELP
  • 5
  • 4

4 Answers4

0

Seems to me you only need to call DoHearingTest() from your handler function and that should do the trick

o_weisman
  • 804
  • 7
  • 19
  • That cannot work as i have another method that determines test sequence. Hence, if i call the method DoHearingTest(), it would have to be DoHearingTest(testseq). Would you like to see the codes or you are able to understand? Sorry for the bad explantion – PLS HELP Jul 01 '14 at 06:39
  • Who calls DoHearingTest() ? Is there a way to get the testseq from the intervalTimer_Elapsed handler function? You could also passing parameters to your handler as described here: http://stackoverflow.com/questions/4215845/c-sharp-passing-extra-parameters-to-an-event-handler – o_weisman Jul 01 '14 at 08:05
  • Thanks but i have another timer elapsed handler which calls the doHearingTest(). – PLS HELP Jul 01 '14 at 08:14
  • I think you should add that handler code as well if you want us to get the full picture – o_weisman Jul 01 '14 at 08:53
0

You can check this link- Example sets up an event handler for the Timer.Elapsed event, creates a timer, uses the Interval property to set the timer interval, and starts the timer. The event handler displays the SignalTime property each time it is raised.

http://msdn.microsoft.com/en-us/library/system.timers.timer.interval(v=vs.110).aspx

0

Use Windows.Form.Timer instead What you are using. like;

        System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
        t.Interval = 2000; // time to occuer the tick event
        t.Tick += new EventHandler(t_Tick); // create event

In you Tick Event after every Two minute Write you code for sound;

    void t_Tick(object sender, EventArgs e)
    {
        t.stop();
        doHearingTest(TestSeq); // this is your code to run at every two minute
        t.start();
    }

Please do the other changes as needed..!!

H. Mahida
  • 2,356
  • 1
  • 12
  • 23
  • I think you might have read the question wrongly. Firstly, i need the to have a pause of 2 seconds after every tone is played. This is why there are the timers. Secondly, my code wont be running for just 2 minutes. Thirdly, i cannot just call the method doHearingTest(TestSeq) as the test seq is decided from another method. Thanks though. – PLS HELP Jul 01 '14 at 06:56
-2

try

Thread.Sleep(2000);

which smakes the current thread sleep