Created
November 11, 2018 11:02
-
-
Save canokay/e6fd7e14c5c2be910fa76862576f0a70 to your computer and use it in GitHub Desktop.
C# Thread Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Ders5_Uygulama1 | |
{ | |
public partial class Form1 : Form | |
{ | |
Thread islem1; | |
Thread islem2; | |
Thread islem3; | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
Form1.CheckForIllegalCrossThreadCalls = false;//Derleyicinin Thread kullanmasına izin vermiş olur. | |
islem1 = new Thread(new ThreadStart(metot1)); | |
islem2 = new Thread(new ThreadStart(metot2)); | |
islem3 = new Thread(new ThreadStart(metot3)); | |
islem1.Start(); | |
islem2.Start(); | |
islem3.Start(); | |
} | |
int i = 100; | |
int j = 100; | |
void metot1() | |
{ | |
while (true) | |
{ | |
listBox1.Items.Add(++i); | |
Thread.Sleep(1000); | |
} | |
} | |
void metot2() | |
{ | |
while (true) | |
{ | |
listBox2.Items.Add(15*j++); | |
Thread.Sleep(2000); | |
} | |
} | |
void metot3() | |
{ | |
while (true) | |
{ | |
label1.Text = DateTime.Now.ToLongTimeString(); | |
} | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
islem1.Abort(); | |
islem2.Abort(); | |
islem3.Abort(); | |
} | |
private void button2_Click(object sender, EventArgs e) | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment