1-) C# Athena - Thread Kullanımı
Thread Kullanımı
1-) bunu kesinlikle yap
public Form1() {
InitializeComponent();
CheckForIllegalCrossThreadCalls=false;
}
2-) progressbar arttırma
public void MyProg1(TextEdit text, System.Windows.Forms.ProgressBar bar) {
bar.Maximum = 100;
bar.Minimum = 0;
bar.Value = 0;
for (int i = 0; i < 100; i++) {
text.Text = i + "";
Thread.Sleep(1000);
bar.Value++;
}
}
3-) thread start yapma
Thread thread1 = (new Thread(() => {
Thread.CurrentThread.IsBackground = true;
MyProg1(textEdit1,progressBar1);
}));
thread1.Start();
4-) hepsi
using System;
using System.Threading;
using System.Windows.Forms;
using DevExpress.XtraEditors;
namespace MyThread {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
}
public void MyProg1(TextEdit text, System.Windows.Forms.ProgressBar bar) {
bar.Maximum = 100;
bar.Minimum = 0;
bar.Value = 0;
for (int i = 0; i < 100; i++) {
text.Text = i + "";
Thread.Sleep(1000);
bar.Value++;
}
}
private void button2_Click(object sender, EventArgs e) {
Thread thread1 = (new Thread(() => {
Thread.CurrentThread.IsBackground = true;
MyProg1(textEdit1,progressBar1);
}));
thread1.Start();
}
private void button7_Click(object sender, EventArgs e) {
Thread thread2 = (new Thread(() => {
Thread.CurrentThread.IsBackground = true;
MyProg1(textEdit2,progressBar2);
}));
thread2.Start();
}
private void button11_Click(object sender, EventArgs e) {
Thread thread3 = (new Thread(() => {
Thread.CurrentThread.IsBackground = true;
MyProg1(textEdit3,progressBar3);
}));
thread3.Start();
}
}
}