c# - How to load an image, then wait a few seconds, then play a mp3 sound? -
After pressing a button, I would like to show an image (using a picture box), wait a few seconds and then mp3 3 sound, but I do not get it to work. I use the system to wait a few seconds. threading. Thread Sleep (5000)
The problem is that the image always appears for waiting time but I want to show it first, then wait, then run MP3 ... I < Code> WaitOnLoad = true but it does not work, should it not load the image first and continue to read the next code line?
The code I used here (which does not work):
Private Zero Button 1_Click (Object Sender, EventArgs e) {pictureBox1.WaitOnLoad = true ; PictureBox1.Load ("image.jpg"); System.Threading.Thread.Sleep (5000); << Code
I also tried to load the image with "LoadSync" and put the code in "LoadCompleted" event to wait and run MP3, but it Then it does not work ...
I will use LoadCompleted Event and start a timer with 5 second interval after loading the image So that the UI thread can not be blocked:
Private Zero Button 1_Click (Object Sender, EventArgs) {PictureBox1.WaitOnLoad = false; PictureBox1.Loady + new asynchronous Aventhandler (picture box 1_load full); PictureBox1.LoadAsync ("image.jpg"); } Zero image box 1_load full (object sender, async computed event args) {// System timers. The timer is used because it supports multithreaded invocation system timers. Timer timer = new system Times. Timer (5000); Timer Elapsed + = New System Timer Espladeevent Handler (Timer_Apple); // set it so that the timer will close when the alplaced event timer is removed. AutoReset = false; Timer Competent = true; } Zero timer_albsed (object sender, System.Timers.ElapsedEventArgs e) {MessageBox.Show ("test"); // Just to test, here should be the code to download MP3
Comments
Post a Comment