c# - Thread.Sleep not working properly -



c# - Thread.Sleep not working properly -

so have picturebox should switch photos after amount of time.

for(int i=1;i<=7;i++) { if (i == 1) { picturebox1.image = properties.resources.unu; console.beep(); } if (i == 2) { picturebox1.image = properties.resources.doi; console.beep(); } if (i == 3) { picturebox1.image = properties.resources.trei; console.beep(); } if (i == 4) { picturebox1.image = properties.resources.patru; console.beep(); } if (i == 5) { picturebox1.image = properties.resources.cinci; console.beep(); } if (i == 6) { picturebox1.image = properties.resources.sase; console.beep(); } thread.sleep(100); }

note: i've inserted console.beep see if programme enters ifs.

i hear beeps image doesn`t change, remains default. why?

by using blocking phone call this, programme can't reenter ui code , update image until after it's finished - means won't seem change. furthermore, depending on you're using ui (you should tag question this!) may need phone call picturebox1.update() or .refresh() in order forcefulness command redraw.

also note since operations can very fast depending on you're doing, you'll want insert thread.sleep(...) calls or way wait user input between each image change, or you'll see blur of images @ best, , lastly image appear @ worst. if you're using framework requires phone call .update(), you'll need between image swaps well.

c# multithreading sleep

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -