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)
{
int i = 100;
int j = 200;
int[] arg = {i,j};
t1 = new Thread(this.th1);
t1.Start(arg);
}
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)
{
int i = 500;
int j = 600;
int[] arg = { i, j };
t2 = new Thread(this.th2);
t2.Start(arg);
}
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(object tmp);
private void th1(object tmp)
{
while (true)
{
if (this.InvokeRequired)
{
this.Invoke(new weituo(js1),tmp);
Thread.Sleep(1000);
}
else
{
js1(tmp);
}
}
}
private void th2(object tmp)
{
while (true)
{
if (this.InvokeRequired)
{
this.Invoke(new weituo(js2),tmp);
Thread.Sleep(1000);
}
else
{
js2(tmp);
}
}
}
private void js1(object tmp)
{
int[] arg = (int[])tmp;
listBox1.Items.Add("這裏是線程 1 在傳遞參數:"+arg[0]+"和"+arg[1]);
}
private void js2(object tmp)
{
int[] arg = (int[])tmp;
listBox1.Items.Add("這裏是線程 1 在傳遞參數:" + arg[0] + "和" + arg[1]);
}
}
}
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)
{
int i = 100;
int j = 200;
int[] arg = {i,j};
t1 = new Thread(this.th1);
t1.Start(arg);
}
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)
{
int i = 500;
int j = 600;
int[] arg = { i, j };
t2 = new Thread(this.th2);
t2.Start(arg);
}
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(object tmp);
private void th1(object tmp)
{
while (true)
{
if (this.InvokeRequired)
{
this.Invoke(new weituo(js1),tmp);
Thread.Sleep(1000);
}
else
{
js1(tmp);
}
}
}
private void th2(object tmp)
{
while (true)
{
if (this.InvokeRequired)
{
this.Invoke(new weituo(js2),tmp);
Thread.Sleep(1000);
}
else
{
js2(tmp);
}
}
}
private void js1(object tmp)
{
int[] arg = (int[])tmp;
listBox1.Items.Add("這裏是線程 1 在傳遞參數:"+arg[0]+"和"+arg[1]);
}
private void js2(object tmp)
{
int[] arg = (int[])tmp;
listBox1.Items.Add("這裏是線程 1 在傳遞參數:" + arg[0] + "和" + arg[1]);
}
}
}