Call function periodically without using threads and sleep() method in c

前端 未结 5 1706
离开以前
离开以前 2021-01-22 11:53

I want to call a function, lets say every 10 or 20 seconds. When I searched, I came up with threads and sleep() method everywhere.

I also checked for time

5条回答
  •  情书的邮戳
    2021-01-22 12:30

    Try this:

    while(true) {
       if(System.getNanotime % 20 == 0) {
          myFunction();
       } 
    }
    

    This is in Java-Syntax, i didn't program c since more than 5 years, but maybe it helps you :)

提交回复
热议问题