有一段循环代码,执行一段时间后就会出现无响应。我想在循环中加入线程,即每循环一次建立一个新的线程,每循环完成一次关闭这个线程。代码如下,应该如何实现? while (persents <= 100)
{
button5_Click(sender, e);
Applications.DoEvents();
Thread.Sleep(500);
button2_Click(sender, e);
Applications.DoEvents();
Thread.Sleep(500);
int i = int.Parse(npcid.Text);
i = i + 1;
npcid.Text = i.ToString();
Applications.DoEvents();
Thread.Sleep(500);
nownamelong = nownamelong + 1;
string nowsst = nownamelong.ToString();
label2.Content = "当前正在对第" + nowsst + "个数据进行操作!"; Applications.DoEvents();
Thread.Sleep(500);
per = (double)nownamelong / wherenamelong;
persents = (double)per * 100;
percon.Text = persents + "%";
progressBar1.Value = persents;
Applications.DoEvents();
Thread.Sleep(500);
}
{
button5_Click(sender, e);
Applications.DoEvents();
Thread.Sleep(500);
button2_Click(sender, e);
Applications.DoEvents();
Thread.Sleep(500);
int i = int.Parse(npcid.Text);
i = i + 1;
npcid.Text = i.ToString();
Applications.DoEvents();
Thread.Sleep(500);
nownamelong = nownamelong + 1;
string nowsst = nownamelong.ToString();
label2.Content = "当前正在对第" + nowsst + "个数据进行操作!"; Applications.DoEvents();
Thread.Sleep(500);
per = (double)nownamelong / wherenamelong;
persents = (double)per * 100;
percon.Text = persents + "%";
progressBar1.Value = persents;
Applications.DoEvents();
Thread.Sleep(500);
}
解决方案 »
- ZEDgraph怎么把右键的菜单改成中文的?
- DataGridView1绑定BindingSource1 可以设置绑定顺序吗?
- 文件流若只读不写发送文字信息出错,请问怎样解决?
- 有哪位高手知道Combobox文本怎么居中。。急。。
- 关于messagebox的问题,怎样让其在弹出后的一定时间内自动关闭?
- 急!急!!急!!!:用C#开发WinCE手持终端程序时如何连接Oracle数据库?
- arraylist动态数组问题~
- 我只想通过WORD打开指定目录(如:d:\myfile\aa\xxx.doc)的文件,代码怎么写啊???
- 如何把负数转换成整数?
- 求C#中用COM+实现 注册和登陆
- 如何读取指纹考勤机数据
- asp.net怎么把resx作为语言包?
int i = 100;
while (i > 0)
{
System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(YouFun));
th.Start();
i--;
//在合适的地方结束线程,或者让线程自己结束
th.Abort();
}
http://topic.csdn.net/u/20091203/11/a1371284-07c3-4ed2-bb5e-4f522c57189f.html
while (i > 0)
{
Thread thread = new Thread(new ParameterizedThreadStart(SomeMethod));}或
var a = new Thread(A);
a.Start();
static void A()
{
}
http://topic.csdn.net/u/20091203/11/a1371284-07c3-4ed2-bb5e-4f522c57189f.html
while (i > 0)
{
Thread thread = new Thread(new ParameterizedThreadStart(SomeMethod));}或
var a = new Thread(A);
a.Start();
static void A()
{
}