线程错误 [英] Thread Error
本文介绍了线程错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人
我写了一些有关线程的代码,但遇到一个错误.
谁能帮我吗?
我的代码如下.
Dear All
I wrote some code about thread, but I face one error.
Can anyone help me?
My code is below.
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Thread T = new Thread(TF);
T.Start();
}
private void TF()
{
groupBox1.Visible = true; //here the error arose
}
当我运行项目时,遇到错误跨线程无效"
When I run the project, I met the error as "cross - Thread invalid"
推荐答案
主线程以外的其他线程.
这里有一些关于此的链接:
http://weblogs.asp.net/justin_rogers/pages/126345.aspx [ ^ ]
从辅助线程调用UI的另一种方法 [
You have to invoke calls into the user interface when working from another thread than the main thread.
Here some links about this:
http://weblogs.asp.net/justin_rogers/pages/126345.aspx[^]
Another way to Invoke UI from a Worker Thread[^]
Good luck!
您可以使用下面的代码来防止出现此错误...
您应该在调用"Application.Run(new ...);"之前在program.cs中使用它.
you can use the code below to prevent this error...
you should use it in program.cs before calling "Application.Run(new ...);"
Form.CheckForIllegalCrossThreadCalls = false;
这篇关于线程错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文