0

我现在要做的是让我的程序在后台添加每次发生后的 5 秒,这样一旦发生 25 秒,就会触发一个事件。

有什么建议么?

这是正在发生的事情的一些代码

        private void autoshapingPanel_Paint(object sender, PaintEventArgs e)
        {

        }

        //Code for Peck Counter

        private int counter = 0;

        public event EventHandler Clicked5TimesEvent;

        private void OnClicked5TimesEvent()
        {
            if (Clicked5TimesEvent != null)
            {
                Clicked5TimesEvent(this, EventArgs.Empty);
            }
        }

        //Stimulus with Peck Counter
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            counter++;
            if (counter % 5 == 0)
            {
                //Code for Hopper
                //Code to Write Data
                string file_name = "C:\\Users\\Carter Daniels\\DATA\\AUTOSHAPINGdata.txt";
                System.IO.StreamWriter objWriter;
                objWriter = new System.IO.StreamWriter(file_name, true);
                objWriter.WriteLine("5 pecks");
                objWriter.WriteLine("1 Reinforcement");
                objWriter.Close();
                //ITI Panel
                ITIpanel.Visible = true;
            }
        }

        private void ITIpanel_Paint(object sender, PaintEventArgs e)
        {
            if (ITIpanel.Visible == true) 
            {
                ITItimers.Enabled = true;
            } 
        }

        private void ITItimers_Tick(object sender, EventArgs e)
        {
            ITIpanel.Visible = false;
            string file_name = "C:\\Users\\Carter Daniels\\DATA\\AUTOSHAPINGdata.txt";
            System.IO.StreamWriter objWriter;
            objWriter = new System.IO.StreamWriter(file_name, true);
            objWriter.WriteLine("5s ITI");
            objWriter.Close();
            ITItimers.Enabled = false; 
            autoshapingPanel.Visible = true;
        }
    }
}

我希望我的程序做的是计算 ITIpanel 或 ITItimers 发生的次数,并在一个或另一个之后触发一个新事件,最好计时器已经发生 20 次

4

1 回答 1

1

一个基本问题似乎有很多文字 - 如果我理解的话。只需进行另一项类似于您现有活动的活动。

    private int _timerCounter = 0;
    private void ITItimers_Tick(object sender, EventArgs e)
    {
        if( _timersCounter++ == 5 ) {
             OnTimerFired20TimesEvent();
             _timersCounter = 0;
        }

        ITIpanel.Visible = false;
        // ...
    }

public event EventHandler TimerFired20TimesEvent;

        private void OnTimerFired20TimesEvent()
        {
            if (TimerFired20TimesEvent != null)
            {
                TimerFired20TimesEvent(this, EventArgs.Empty);
            }
        }
于 2012-04-11T05:44:15.410 回答