winforms - Pause button for a game c# -
i want create simple pause button, , perhaps button resume if necessary. i've been looking around , see thread.sleep(), doesn't work me because want pause remain paused until user desires.
thread.suspend() doesn't work because obsolete now.
i've seen solution of creating second form, however, doesn't seem working me. once second form opens up, entire program closes.
i'm not sure if makes difference, program uses 2 threads (main thread running form1 along thread). ideally, needs paused.
the simpliest thing have variable/property other thread can access.
bool shouldpause = false; the other thread should have in it's game loop :
while(true) { if(!shouldpause) { updategame(); } draw(); } then game proceed when shouldpause variable false. did several times , worked perfectly.
you don't want pause thread via "suspend" functions because prevent him draw on screen , appear it's not responding.
Comments
Post a Comment