C # Cross thread operation detected.

Source: Internet
Author: User

Recently changed someone's code debugging times this mistake, debugging for a long time did not find any problems, Baidu did not find the corresponding solution.

Thread th = new Thread (new ThreadStart () =
{
Table. Rows.clear ();
Checksavedata ();
Binddatagrid (table);
}));
Th. IsBackground = true;
Th. Start ();

Later, after being explained, I thought about what the reason was. The general meaning of the error message is that the control of the form is manipulated inside the thread, and there was no code where the control of the form was called.

The problem is table. Rows.clear (), this line of code, because the form in the number of Gridcontrol binding data source is set to table, so when the online thread all rows of the table is Clear, triggered the

Gridcontrol data Change event, equal to the indirect operation of Gridcontrol, so the error is reported, as long as the line of code written to the thread on the line, the effect is the same.

C # Cross thread operation detected.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.