You cannot call invoke or begininvoke on the control before creating a window handle.

Source: Internet
Author: User

This article reprinted: http://blog.csdn.net/playing9c/article/details/7471918

Http://blog.csdn.net/beelinkerlidejun/article/details/4772491

Http://www.cnblogs.com/fish124423/archive/2012/10/16/2726543.html

C # multithreading of forms has always been a difficult problem, and there must always be strange errors. When developing alexseo software today, it appears that you cannot call invoke or begininvoke on the control before creating a window handle. The main error code is as follows:

   protected override void OnLoad(EventArgs e)        {            base.OnLoad(e);            txtRFID_Click(null, null);        }
View code

 

Private void txtrfid_click (Object sender, eventargs e) {thread = new thread () => {If (this. ishandlecreated) This. begininvoke (New methodinvoker () => {this.txt RFID. enabled = false;}); int iret =-1; string strtid = ""; iret = writecardhelper. instance. readtid (ref strtid); // read time-consuming code; Note: time-consuming Code cannot be placed in this. begininvoke (New methodinvoker () => time-consuming code}); // it is executed in; otherwise, no asynchronous effect is generated. Only the code of the operation control can be placed in begininvoke. If (this. ishandlecreated) This. begininvoke (New methodinvoker () => {this.errorprovider.seterror(this.txt RFID, ""); If (0 = iret) {writecardhelper. instance. setalarm (); this.txt RFID. TEXT = strtid; this.txt RFID. backcolor = color. white; this.errorprovider.seterror(this.txt RFID, "");} else {this.txt RFID. TEXT = ""; this.txt RFID. backcolor = color. pink;} this.txt gasbottleno. focus (); this.txt RFID. enabled = true ;})) ;}; thread. isbackground = true; thread. start ();}

 

Client:

Frmgasbottlesinstall frminstall = new frmgasbottlesinstall (gasbottlesid); frminstall. showdialog (); // asynchronously opens a window.

 

When the software is suddenly closed during debugging, labb. Invoke (labchange); the statement goes out first, "You cannot call invoke or begininvoke on the control before creating the window handle ." Error. There are two possibilities for this situation. The first is that the interface is too late to respond to invoke, and the second is that the interface thread has ended, so the response cannot be responded. The final solution is to add an IF (labb. ishandlecreated) before labb. Invoke (labchange.

You cannot call invoke or begininvoke on the control before creating a window handle.

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.