-3

Hello everyong im working on a project on my C# class. I have a button that generates 3 random pictures after i click this (Slot Machine) and i need to make it generate those pictures after 3 seconds so it seems like its loading.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Marios P
  • 1
  • 4

3 Answers3

1

This won't freeze your UI:

async void button1_Click(object sender, EventArgs e)
{
    await Task.Delay(TimeSpan.FromSeconds(3));
    do something;
}
Dour High Arch
  • 21,513
  • 29
  • 75
  • 90
0

You can pause your current thread using Thread.Sleep :

using System.Threading;

TimeSpan interval = new TimeSpan(0, 0, 0, 3); // 3 seconds
Thread.Sleep(interval);
Georg Patscheider
  • 9,357
  • 1
  • 26
  • 36
0

I would use the Thread.Sleep() function. Parameter is given in miliseconds ´

 private void button1_Click(object sender, EventArgs e)
 {
        System.Threading.Thread.Sleep(5000);
        //following code
 }

If you don't want to freeze the UI. You can use this stackoverflow answer