using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
namespace WinFormsApp9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int j, k;
private void button1_Click(object sender, EventArgs e)
{
Thread kanal1 = new Thread(new ThreadStart(sayici1));
Thread kanal2 = new Thread(new ThreadStart(sayici2));
CheckForIllegalCrossThreadCalls = false;
kanal1.Start();
kanal2.Start();
}
private void sayici1()
{
for (int i = 0; i < 30; i++)
{
Thread.Sleep(500);
label1.Invoke(new sayici1_delagate(yeni_sayici1));
}
}
private void sayici2()
{
for (int i = 0; i <30; i++)
{
Thread.Sleep(500);
label2.Invoke(new sayici2_delegate(yeni_sayici2));
if (i == 15)
Thread.Sleep(3000);
}
}
private delegate void sayici1_delagate();
private void yeni_sayici1()
{
j++;
label1.Text = j + " ";
}
private delegate void sayici2_delegate();
private void yeni_sayici2()
{
k++;
label2.Text = k + "";
}
}
}
//Thread.sleep metodunu timespan ile kullanabilirsiniz
//thread.sleep(timespan.frommilliseconds(1000)); 1 saniye bekletir
//thread.sleep(timespan.fromminutees(1); 1 dakika bekletir.
//thread.sleep(timespan.fromhours(1)); 1 saat bekletir.
//thread.sleep(time.framDays(1)); 1 gün bekletir..