Other thread controls are called between the form program threads.

Source: Internet
Author: User

In a formProgramEncountered a problem, using a timer to operate the Form Control, did not respond in release, debug reported an error. An error occurred while calling non-internal controls. Data Query discovery must be non-thread-safe. invokerequired can be used to ensure thread security to prevent errors.

Controls in Windows Forms are bound to a specific thread and are not thread safe. therefore, if you are calling a control's method from a different thread, you must use one of the control's invoke methods to invoke al the call to the proper thread. this property can be used to determine if you must call an invoke method, which can be useful if you do not know what thread owns a control.

(When the form control is not thread-safe, it is bound to the specified thread. When you call it through other threads, you must use the call method of the control to configure the call for queuing. If you must call the invokerequired property of a method, you can use it to determine whether the control is available now .)

Public Delegate void mycallback ();

Public void myfunction ()
{< br> If (this. control name. invokerequired)
{< br> mycallback d = new mycallback (myfunction);
This. invoke (d);
}< br> else
{< br> // perform the operation
}< BR >}

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.