Thread.Sleep() in C#

后端 未结 4 647
孤街浪徒
孤街浪徒 2020-12-06 20:31

I want to make an image viewer in C# Visual Studio 2010 which displays images one by one after seconds:

i = 0;

if (image1.Length > 0) //image1          


        
4条回答
  •  情书的邮戳
    2020-12-06 20:54

    If you want to avoid using Timer and defining an event handler you can do this:

    DateTime t = DateTime.Now;
    while (i < image1.Length) {
        DateTime now = DateTime.Now;
        if ((now - t).TotalSeconds >= 2) {
            pictureBox1.Image = Image.FromFile(image1[i]);
            i++;
            t = now;
        }
        Application.DoEvents();
    }
    

提交回复
热议问题