Thread Sleep problem - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Thread Sleep problem

dabazdabaz Posts: 2Member
Hello,
I recently started programming in C# and was trying to build a program that would show a picture on the screen for 5 seconds then show another picture. However, when I run my program I see nothing for 5 seconds then the second picture shows up immediately. Any help would be appreciated.

using System;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

public class picview : System.Windows.Forms.Form
{

private PictureBox picture = new PictureBox();


[STAThread]
public static int Main(string[] args)
{

System.Windows.Forms.Application.Run(new picview());
return 0;
}

public picview()
{
int resw,resh;
this.FormBorderStyle = 0; //Remove border around frame
resw = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; //Get screen resolution size
resh = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
this.Size = new System.Drawing.Size(resw, resh); //Set form to screen size

picture.Location=new Point(0,0); //Set picture location
picture.Size= new Size(resw,resh); //Make picture full screen
picture.Image=Image.FromFile("e:\p1.jpg");
Controls.Add(picture);
Thread.Sleep(5000);
picture.Image=Image.FromFile("e:\p2.jpg");

}

}

Comments

  • WEBMASTERWEBMASTER Posts: 549Member
    You need to do a Application.DoEvents(); before and after the thread sleep to refresh the screen.


    Tore Nestenius
    [blue][italic][b]/WEBMASTER[/b][/italic][/blue] Programmers Heaven
  • dabazdabaz Posts: 2Member
    Thank you for the reply, however adding Application.DoEvents() before and after the thread sleep did not work. Any other ideas?

    : You need to do a Application.DoEvents(); before and after the thread
    : sleep to refresh the screen.
    :
    :
    : Tore Nestenius
    : [blue][italic][b]/WEBMASTER[/b][/italic][/blue] Programmers Heaven

Sign In or Register to comment.