Have you tried using Application.DoEvents();
before the wait time? I believe that should force C# to draw the image before going to sleep.
Joel Alejandro
2010-01-23 12:50:16
Have you tried using Application.DoEvents();
before the wait time? I believe that should force C# to draw the image before going to sleep.
I would use the LoadCompleted event and start a timer with 5 sec interval once the image is loaded, so that the UI thread is 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 is used as it supports multithreaded invocations
System.Timers.Timer timer = new System.Timers.Timer(5000);
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
//set this so that the timer is stopped once the elaplsed event is fired
timer.AutoReset = false;
timer.Enabled = true;
}
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
MessageBox.Show("test"); //just to test, here should be the code to play the mp3
}
it works when application.doevents() used.
private void button1_Click(object sender, EventArgs e) { pictureBox1.Load("image.jpg"); Application.DoEvents(); pictureBox1.WaitOnLoad = true; System.Threading.Thread.Sleep(5000); MessageBox.Show("test"); //just to test, here should be the code to play the mp3 }