简单一点这样试试
private void button1_Click(object sender, System.EventArgs e)
{
MethodInvoker mi = new MethodInvoker(addlist);
mi.BeginInvoke(null,null);
} void addlist()
{
for(int i =0;i<200000;i++)
{
listBox1.Items.Add(i.ToString());
}
}
private void button1_Click(object sender, System.EventArgs e)
{
MethodInvoker mi = new MethodInvoker(addlist);
mi.BeginInvoke(null,null);
} void addlist()
{
for(int i =0;i<200000;i++)
{
listBox1.Items.Add(i.ToString());
}
}
解决方案 »
- dev控件gridControl中加入repositoryItemCheckEdit列
- Gridview 問題
- C# 获取鼠标指向控件句柄
- 紧急求助
- 谁有asp.net2.0典型项目开发(杨云/王毅)的光盘 在线等
- 如何更改IP地址
- 关于两个datetimepicker之间的相差值得问题
- Pocket Pc2003 如何用WebService访问Oracle数据库
- 这是什么BUG?sql语句问题,小弟第一次,见笑了,谢谢
- 如何确定当前DataGrid所选中的记录??急急急
- 2维数组究竟应该才对????????????
- asp.net 导成excel后 怎么来控制图片在excel里面的大小呢??急急急!!!请大虾留言...深表感谢
不行呀,错误如下:你测试一下吧
线程间操作无效: 从不是创建控件“listBox1”的线程访问它。
private void setTextUnsafeBtn_Click(
object sender,
EventArgs e)
{
this.demoThread =
new Thread(new ThreadStart(this.ThreadProcUnsafe)); this.demoThread.Start();
}// This method is executed on the worker thread and makes
// an unsafe call on the TextBox control.
private void ThreadProcUnsafe()
{
this.textBox1.Text = "This text was set unsafely.";
}private void setTextSafeBtn_Click(
object sender,
EventArgs e)
{
this.demoThread =
new Thread(new ThreadStart(this.ThreadProcSafe)); this.demoThread.Start();
}// This method is executed on the worker thread and makes
// a thread-safe call on the TextBox control.
private void ThreadProcSafe()
{
this.SetText("This text was set safely.");
}private void SetText(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.textBox1.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.textBox1.Text = text;
}
}
private void setTextBackgroundWorkerBtn_Click(
object sender,
EventArgs e)
{
this.backgroundWorker1.RunWorkerAsync();
}// This event handler sets the Text property of the TextBox
// control. It is called on the thread that created the
// TextBox control, so the call is thread-safe.
//
// BackgroundWorker is the preferred way to perform asynchronous
// operations.private void backgroundWorker1_RunWorkerCompleted(
object sender,
RunWorkerCompletedEventArgs e)
{
this.textBox1.Text =
"This text was set safely by BackgroundWorker.";
}
而不是建立委托。
其里头 backgroundWorker也是用委托处理的。