c# - Threads with common variable -


i'm building nfs joystick manipulating mousewheel events. on main thread call second thread pulses keyboard keys generated frequency. problem frequency dynamically changes in time when move or down mousewheel simulator thread doesn't notice change. fragment of code:

int centro = 0; static bool left; static bool ismoving; static int grado; static int frec;  thread simulator = new thread(new threadstart(move)); public form1() {     initializecomponent(); } static void mleft() {     keyboardsimulator.keydown(keys.g);     thread.sleep(10);     keyboardsimulator.keyup(keys.g); } static void mright() {     keyboardsimulator.keydown(keys.j);     thread.sleep(10);     keyboardsimulator.keyup(keys.j); } static void move() {     while (ismoving)     {         if (left)         {             mleft();             thread.sleep(frec);         }         else         {             mright();             thread.sleep(frec);         }                   }  } void map() {      if (grado == 0)     {         ismoving = false;         frec = 0;     }     else     {         int ut = 1000;//1seg         left = grado > 0;         grado = math.abs(grado);         frec = ut / grado / 10;         ismoving = true;     }   } private void window_closed_1(object sender, eventargs e) {     simulator.abort(); } private void form1_load(object sender, eventargs e) {     hookmanager.mousewheel += window_mousewheel_1;     simulator = new thread(new threadstart(move)); } private void window_mousewheel_1(object sender, mouseeventargs e) {     centro += e.delta;     grado = centro / 120;     l1.text = grado + "";     map(); } 


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -