c# - How to load an image, then wait a few seconds, then play a mp3 sound? -


after pressing button, show image (using picturebox), wait few seconds , play mp3 sound, dont work. wait few seconds use system.threading.thread.sleep(5000). problem is, image appears after wait time, want show first, wait, play mp3... tried use waitonload = true doesn't work, shouldn't load image first , continue read next code line?

here code i've tried (that doesn't work):

private void button1_click(object sender, eventargs e) {     picturebox1.waitonload = true;     picturebox1.load("image.jpg");     system.threading.thread.sleep(5000);     messagebox.show("test");//just test, here should code play mp3 } 

i tried loading image "loadasync" , put code wait , play mp3 in "loadcompleted" event, doesn't work either...

i use loadcompleted event , start timer 5 sec interval once image loaded, ui thread not blocked:

   private void button1_click(object sender, eventargs e)     {         picturebox1.waitonload = false;         picturebox1.loadcompleted += new asynccompletedeventhandler(picturebox1_loadcompleted);         picturebox1.loadasync("image.jpg");     }      void picturebox1_loadcompleted(object sender, asynccompletedeventargs e)     {         //system.timers.timer used supports multithreaded invocations         system.timers.timer timer = new system.timers.timer(5000);           timer.elapsed += new system.timers.elapsedeventhandler(timer_elapsed);          //set timer stopped once elaplsed event fired         timer.autoreset = false;           timer.enabled = true;     }      void timer_elapsed(object sender, system.timers.elapsedeventargs e)     {         messagebox.show("test"); //just test, here should code play mp3     } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -