C # Multithreading Problem integration

Source: Internet
Author: User

One, cross-process access Components

Error: Invalid inter-thread operation: access it from a thread that is not creating a control "XXX"

Workaround:

1: Set the Checkforillegalcrossthreadcalls to False

This method simply does not catch the call to the wrong thread and does not resolve the problem from the root cause, and the code continues to throw errors that the component is not instantiated.

2: Delegate (recommended)

Directly on the code

public delegate void Myinvoke ();p rivate void Setbtnstatus () {           if (ishandlecreated)     {         Myinvoke mi = new Myinvo Ke (setstatusmethod);         BeginInvoke (MI);     }     else        Setstatusmethod ();} public void Setstatusmethod () {     btnsave.enable = true;}

Declares a delegate method Myinvoke

ishandlecreated: Gets a value that indicates whether the control has a handle associated with it. If the component is not associated, you can execute the method directly, creating or manipulating the component. The execution method is delegated if there is a relationship.

C # Multithreading Problem integration

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.