c# - How to call function 200 times in 1 second -


this code doesn't call function 200 times in 1 second, first time 167 calls, second time 201 don't 200.

public thread thread; public timer timer; int = 0;  private void button_click(object sender, routedeventargs e) {    timer = new timer(mess);    timer.change(10000, 10000);    thread = new thread(calc);    thread.start(); }  private void mess(object state) {    messagebox.show("call in on second : " + (i / 10).tostring());    = 0; }  private void calc(object obj) {    while (true)    {       i++;       thread.sleep(5);    } } 

its because of scheduler wich manage different threads in processor. process not running time in processor strange behaviors can occur. programs using threads deterministic (it's why 167 first time ans 201 in second time)


Comments

Popular posts from this blog

html - Cut text on left side inside button while centering -

java - Last square of 8x8 grid not drawn, using two nested FOR loops -

What design pattern is this code in Javascript? -