Two timers with two different intervals C# Form

若如初见. 提交于 2019-12-04 22:04:19

from your comments:

you need to set 1000 for 1 sec as 1 sec = 1000 milliseconds. because by default Interval is 100

private void Form1_Load(object sender, EventArgs e)
        {
            ControlTimerInbox.Interval=1000;//for 1 second
            ControlTimerInbox.Enabled = true;
            ControlTimerInbox.Start();

            StatusTimer.Interval=1000;//for 1 second
            StatusTimer.Enabled = true;
            StatusTimer.Start();


        }

Solution 2: You don't need to call Start() until unless You call Stop().

So remove calling Start()

Controller Timer

 else
            {
            nome = Dns.GetHostByAddress(ipremoto.Address);
            CampoChat.Text += "(" + DateTime.Now + ")" + mesric + "\n";
            ControlTimerInbox.Enabled = true;
            //ControlTimerInbox.Start();  //remove or comment
            }

Sending Status:

private void StatusTimer_Tick(object sender, EventArgs e)
        {
            if (status == true)
            {                
                    mes = "GruppoDue:ON!";
                    send.Send(Encoding.ASCII.GetBytes(mes), mes.Length, "192.168.7.255", 11000);                 
            }
            else
            {              
                    mes = "GruppoDue:OFF!";
                    send.Send(Encoding.ASCII.GetBytes(mes), mes.Length, "192.168.7.255", 11000);
            }
              //StatusTimer.Start();//remove or comment
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!