首页 新闻 会员 周边 捐助

anyone can help ?C#线程问题 , 非常感谢

0
悬赏园豆:50 [已关闭问题] 关闭于 2011-07-09 12:58
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)
{ }

}
}
问题补充:

cheatingdeath的主页 cheatingdeath | 初学一级 | 园豆:110
提问于:2011-07-08 22:19
< >
分享
所有回答(1)
0

不知什么问题,如果使用线程、线程池等可以参考 http://www.cnblogs.com/2018/category/297520.html 

2012 | 园豆:21645 (高人七级) | 2011-07-09 09:49
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册