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
{
public Form1()
{
InitializeComponent();
} private Thread myThread = new Thread(new ThreadStart(runWork)); //错误 1 字段初始值设定项无法引用非静态字段、方法或属性“WindowsApplication1.Form1.runWork()” D:\测试\测试例程(C#)\WindowsApplication1\Form1.cs 19 46 WindowsApplication1 private delegate void MyInvoke(int percent);
private MyInvoke showResult = new MyInvoke(showInvoke); //错误 1 字段初始值设定项无法引用非静态字段、方法或属性“WindowsApplication1.Form1.runWork()” D:\测试\测试例程(C#)\WindowsApplication1\Form1.cs 19 46 WindowsApplication1
private void runWork()
{
for(int i = 0; i< 100; i++)
{
BeginInvoke(showResult, i);
Thread.Sleep(100);
}
} private void showInvoke(int percent)
{
textBoxPercentage.Text = percent + "%";
progressBarPercentage.Value = percent;
if(percent == 100)
{
MessageBox.Show("任务完成!");
myThread.Abort();
}
} private void Form1_Load(object sender, EventArgs e)
{
progressBarPercentage.Minimum = 0;
progressBarPercentage.Maximum = 100;
} private void buttonStart_Click(object sender, EventArgs e)
{
myThread.Start();
}
}
}
解决方案 »
- Linq to Entity可空对象内容的比较
- 用UDP接收GPS终端发过来的数据乱码
- 多用户操作并发限制
- DataTable dataTable = SystemTools.ConvertDataReaderToDataTable(GetDirectorys());
- 想设计一个自动备份数据库的程序,征求一下大家相法!
- FolderBrowserDialog 显示不出目录树,是空的
- 出错处理
- 怎樣用c#獲取計算機的硬件信息如:cpu disk....
- 为什么C#.NET调用WebService的时候 progressBar就没有反应了呢????
- 时间相减的问题
- 关于上传文件的类型检测
- C#GDI+画png图片
private void Form1_Load(object sender, EventArgs e)中
{
public Form1()
{
InitializeComponent();myThread=new Thread(new ThreadStart(runWork));
showResult=new MyInvoke(showInvoke);
} private Thread myThread =null;
private delegate void MyInvoke(int percent);
private MyInvoke showResult =null; private void runWork()
{
for(int i = 0; i< 100; i++)
{
BeginInvoke(showResult, i);
Thread.Sleep(100);
}
} private void showInvoke(int percent)
{
textBoxPercentage.Text = percent + "%";
progressBarPercentage.Value = percent;
if(percent == 100)
{
MessageBox.Show("任务完成!");
myThread.Abort();
}
} private void Form1_Load(object sender, EventArgs e)
{
progressBarPercentage.Minimum = 0;
progressBarPercentage.Maximum = 100;
} private void buttonStart_Click(object sender, EventArgs e)
{
myThread.Start();
}
}