c# 多线程的一个小Demo
原创
©著作权归作者所有:来自51CTO博客作者hxmhh的原创作品,请联系作者获取转载授权,否则将追究法律责任
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace XianChen

{
public partial
class Form3 : Form

{
public Form3()

{

InitializeComponent();

}

Thread t1, t2;
private void button1_Click(
object sender, EventArgs e)

{

t1 =
new Thread(
this.th1);

t1.Start();

}
private void button2_Click(
object sender, EventArgs e)

{

t1.Suspend();

}
private void button7_Click(
object sender, EventArgs e)

{

t1.Resume();

}
private void button3_Click(
object sender, EventArgs e)

{

t1.Abort();

}
private void button4_Click(
object sender, EventArgs e)

{

t2 =
new Thread(
this.th2);

t2.Start();

}
private void button5_Click(
object sender, EventArgs e)

{

t2.Suspend();

}
private void button8_Click(
object sender, EventArgs e)

{

t2.Resume();

}
private void button6_Click(
object sender, EventArgs e)

{

t2.Abort();

}
private delegate void weituo();
private void th1()

{
while (
true)

{
if (
this.InvokeRequired)

{
this.Invoke(
new weituo(js1));

Thread.Sleep(1000);

}
else 
{

js1();

}

}

}
private void th2()

{
while (
true)

{
if (
this.InvokeRequired)

{
this.Invoke(
new weituo(js2));

Thread.Sleep(1000);

}
else 
{

js1();

}

}

}
private void js1()

{
int i = 1;
if (i == 1)

{

listBox1.Items.Add(
"这里是线程 1");

}

}
private void js2()

{
int i = 1;
if (i == 1)

{

listBox1.Items.Add(
"这里是线程 2");

}

}

}

}
这里包含了多线程的所有用法。
在这里我没有写判断,大家自己加进去好了,很简单。