C# WinForms: How to load an image, then wait a few seconds, then play a mp3 sound ?

Posted by ibmkahm on Stack Overflow See other posts from Stack Overflow or by ibmkahm
Published on 2010-01-23T12:43:51Z Indexed on 2010/05/05 8:18 UTC
Read the original article Hit count: 353

Filed under:
|

Hello everybody,

(after pressing a button) i would like to show an image (using a picturebox), wait a few seconds and then play a mp3 sound, but i dont get it to work. To wait a few seconds i use "System.Threading.Thread.Sleep(5000)". The problem is, the image alway appears AFTER the wait time, but i want it to show first, then wait, then play the mp3... i tried to use "WaitOnLoad = true" but it doesnt work, shouldn't it load the image first and the continue to read the next code line ??

Here is the code i've tried, that doesnt 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 to test, here should be the code to play the mp3
}

(i also tried loading the image with "LoadAsync" and put the code to wait and play the mp3 in the "LoadCompleted" event, but that doesnt work either...)

would be very nice if somebody helps me

© Stack Overflow or respective owner

Related posts about picturebox

Related posts about c#