arrays - c# is there a way to stop a foreach loop until the event occurs again? -


i trying program foreach loop , coding button click event. problem have loop goes straight through end of array, want stop @ each string in array until button clicked again , move onto next string. should use break; or continue;?

foreach (string s in weapons) {     picturebox9.image = image.fromfile(s + ".png");     counter++;     continue; } 

stop using foreach loop because freeze ui when stop/pause loop.

use instead.

counter++; if(counter >= weapons.count) {     counter = 0; } string weapon = weapons[counter]; picturebox9.image = image.fromfile(weapon + ".png"); 

you alread have counter. increment if button pressed , if get's high reset it. can select image list , @ least update image.

a improvement load images @ start , put them in list replace weapons list. access item in list via counter well.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -