using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace WindowsApplication1
{
public partial class Form1 : Form
{
int i=0;
public Form1()
{
InitializeComponent();
}
public void runbar()
{
while(true)
{
progressbar.Value += 1;
}
} private void button1_Click(object sender, EventArgs e)
{
new System.Threading.Thread(new System.Threading.ThreadStart(runbar)).Start();//创建一个新的线程并启动
while (true)
{ Thread.Sleep(1000); }
} private void Form1_Load(object sender, EventArgs e)
{
CheckForIllegalCrossThreadCalls = false;
}
}
}我的想法是 progressbar.Value 不段增加,但下面这段代码只能执行一次,我也不知为什么,请高手看看
public void runbar()
{
while(true)
{
progressbar.Value += 1;
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace WindowsApplication1
{
public partial class Form1 : Form
{
int i=0;
public Form1()
{
InitializeComponent();
}
public void runbar()
{
while(true)
{
progressbar.Value += 1;
}
} private void button1_Click(object sender, EventArgs e)
{
new System.Threading.Thread(new System.Threading.ThreadStart(runbar)).Start();//创建一个新的线程并启动
while (true)
{ Thread.Sleep(1000); }
} private void Form1_Load(object sender, EventArgs e)
{
CheckForIllegalCrossThreadCalls = false;
}
}
}我的想法是 progressbar.Value 不段增加,但下面这段代码只能执行一次,我也不知为什么,请高手看看
public void runbar()
{
while(true)
{
progressbar.Value += 1;
}
}
解决方案 »
- 接口错误,是什么原因?
- 请教:SetMeasurableCharacterRanges(CharacterRanges[])溢出
- 求救,如何生成柱状图,拆线图等统计图?
- 怎样使子窗体填满主窗体的工作区??
- [求助]请问这个应该如何实现,或者我该主要看些什么书,谢谢各位!
- 为什么我写的服务不运行?
- 请问一个CheckedListBox 控件的问题
- 如何打开Form名称保存在数据表中的Form呀
- 求《Applied Microsoft .Net Framework Programming》和《programming windows with c# 》这两本书
- 菜鸟的问题:关于DATAGRID里面分页的问题…………在线等待
- 如何改变IDE中的字体?
- 技术探讨
{ ....; }为什么都是这个代码 这不是传说中的死循环么?
{
new System.Threading.Thread(new System.Threading.ThreadStart(runbar)).Start();
}
public void runbar()
{
progressBar1.Maximum = 100;//设置一个最大值
while (true)
{
if (progressBar1.Value == 100)//达到最大值的时候
progressBar1.Value = 0;//可以停止break或者又从0开始
progressBar1.Value += 1;
System.Threading.Thread.Sleep(100);
}
}