Run function every second Visual C#

后端 未结 4 848
长发绾君心
长发绾君心 2021-01-14 12:08

I have problems with timer. I have function in function (draw in func)

void func(){

 /*...do something ... */
for(){
   for() {
  /*loop*/

 draw(A,B, Pen);         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-14 12:40

    I'm not entirely clear on what you're trying to do, but, in general, you can use an object of the Timer class to specify code to be executed on a specified interval. The code would look something like this:

    Timer myTimer = new Timer();
    myTimer.Elapsed += new ElapsedEventHandler(DisplayTimeEvent);
    myTimer.Interval = 1000; // 1000 ms is one second
    myTimer.Start();
    
    public static void DisplayTimeEvent(object source, ElapsedEventArgs e)
    {
        // code here will run every second
    }
    

提交回复
热议问题