Execute specified function every X seconds

后端 未结 4 1860
小鲜肉
小鲜肉 2020-11-27 15:02

I have a Windows Forms application written in C#. The following function checks whenever printer is online or not:

public void isonline()
{
    PrinterSettin         


        
4条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 15:38

    Use System.Windows.Forms.Timer.

    private Timer timer1; 
    public void InitTimer()
    {
        timer1 = new Timer();
        timer1.Tick += new EventHandler(timer1_Tick);
        timer1.Interval = 2000; // in miliseconds
        timer1.Start();
    }
    
    private void timer1_Tick(object sender, EventArgs e)
    {
        isonline();
    }
    

    You can call InitTimer() in Form1_Load().

提交回复
热议问题