Możesz użyć: Thread.Sleep c#.NET [ 1 ] [ 2 ] [ 3 ]
using System.Threading;
. . .
Thread.Sleep(1000); // zatrzymanie na 1 sekundę - c# Sleep(Int32 milliseconds)
przykład zastosowania Thread.Sleep w aplikacji "konsolowej": (demo on-line)
using System;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int hrs = 0, min = 0, sec = 0;
Console.CursorVisible = false;
while (true)
{
sec++;
if (sec == 60)
{
sec = 0;
min++;
if (min == 60)
{
min = 0;
hrs++;
if (hrs == 24) hrs = 0;
}
}
Console.Write("{0:00}:{1:00}:{2:00}", hrs, min, sec);
Thread.Sleep(1000); // c# Sleep(Int32 milliseconds)
Console.Clear();
if (hrs == 1) break; // po 1h zatrzymuje pokazywanie zegara
}
}
}
}
W pętli, żeby uzyskać efekt, o którym piszesz wydaje mi się, że wystarczy ustawić np.:
Thread.Sleep(100); // 100 milisekund
"Szybkie" demo licznika
using System;
using System.Threading;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
label1.Text = "0";
button1.Text = "Dodaj 10 punktów";
button1.Tag = 10;
}
private void button1_Click(object sender, EventArgs e)
{
addPoints(Convert.ToInt32(button1.Tag));
Random r = new Random();
button1.Tag = r.Next(10, 50);
button1.Text = "Dodaj " + button1.Tag + " punktów";
}
private void addPoints(int points)
{
int current_points = Convert.ToInt32(label1.Text);
for (int i = 1; i <= points; i++)
{
label1.Text = (current_points + i).ToString();
label1.Refresh();
Thread.Sleep(10 + (i*2));
}
}
}
}