I have a bit of code which is meant to show a form for a period of time and play a sound.
However the Form stays open.
static void Main(string[] args)
{
SoundPlayer sp = new SoundPlayer();
ShowImage(@"Resources\Fish.png", "Fish", 256, 256, 1000);
sp.SoundLocation = @"Resources\fish.wav";
sp.Play();
}
public static void ShowImage(string img, string title, int width, int height, int timeout)
{
ImageContainer ic = new ImageContainer();
ic.imgView.Image = Image.FromFile(img);
ic.Text = title;
ic.Size = ic.imgView.Image.Size;
ic.Height = height;
ic.Width = width;
ic.ShowDialog();
Thread.Sleep(timeout);
ic.Hide();
ic.Opacity = 0;
ic.Dispose();
}
It just stays with the form open doesn’t close or hide.
ImageContainer is a Form with a PictureBox called imgView in it.
I need it to time out for 1 second before it closes.
The line:
Causes the form to show in a modal fashion, so that method blocks and prevents everything else from running until the form closes.
Change that line to:
This is non-modal, and the rest of the method will complete.