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 WindowsFormsApplication4
{
public partial class Form1 : System .Windows.Forms .Form
{
private System.Threading.Thread a;
private System.Threading.Thread b;
public Form1( )
{
InitializeComponent();
button1 .Click +=new EventHandler(labelt_Click);
button2.Click += new EventHandler(labela_Click);
button3.Click += new EventHandler(labelt_Click);
button4.Click += new EventHandler(labela_Click);
button5.Click += new EventHandler(labela_Click);
button6.Click += new EventHandler(labelt_Click);
a= new Thread (new System .Threading .ThreadStart (thefor1));
b = new Thread(new System.Threading.ThreadStart(thefor2));
}
public void thefor1()
{
for (int i = 0; i < 10000; i++)
{ progressBar1 .Value = i; }
}
public void thefor2()
{
for (int g = 0; g < 10000; g++)
{progressBar2.Value = g; }
}
private void 线程示例_Load(object sender, EventArgs e)
{
label7.Text = a.ThreadState.ToString();
label2.Text = a.ThreadState.ToString();
}
private void label2_Click(object sender, EventArgs e)
{ }
private void groupBox2_Enter(object sender, EventArgs e)
{ }
private void button1_Click(object sender, EventArgs e)
{ }
private void label1_Click(object sender, EventArgs e)
{ }
private void label2_Click_1(object sender, EventArgs e)
{ }
private void button2_Click(object sender, EventArgs e)
{ }
private void label7_Click(object sender, EventArgs e)
{ }
private void labelt_Click(object sender, EventArgs e)
{
switch (((Button)sender).Text)
{
case "启动":
if (a.ThreadState.ToString() == "Suspend")
{ a.Start(); }
else
{ a.Start(); }
System.Threading.Thread.Sleep(1);
break;
case "暂停": a.Suspend(); break;
case "停止":
try { a.Abort(); }
catch (Exception ex)
{ label7.Text = ex.Message; }; break;
}
label7.Text = a.ThreadState.ToString();
}
private void labela_Click(object sender, EventArgs e)
{
switch (((Button)sender).Text)
{
case "启动":
if (a.ThreadState.ToString() == "Suspend")
{ a.Start(); }
else
{ a.Start(); }
System.Threading.Thread.Sleep(1);
break;
case "暂停": a.Suspend(); break;
case "停止":
try { a.Abort(); }
catch (Exception ex)
{ label2.Text = ex.Message; }; break;
}
label2.Text = a.ThreadState.ToString();
}
private void label3_Click(object sender, EventArgs e)
{ }
private void button6_Click(object sender, EventArgs e)
{ }
private void button3_Click(object sender, EventArgs e)
{ }
private void progressBar1_Click(object sender, EventArgs e)
{ }
}
}