Public partial class ucinfo: usercontrol {public ucinfo () {initializecomponent ();} manualresetevent neversetevt = new manualresetevent (false); Delegate void encrypt (); Public void setinfo (string info) {lblinfo. invoke (New invokedelegate () => {lblinfo. forecolor = color. green;}), null); lblinfo. invoke (New invokedelegate () => {lblinfo. TEXT = Info;}), null); threadpool. registerwaitforsingleobject (neversetevt, (OBJ, BOL) =>{ if (lblinfo. ishandlecreated) {lblinfo. invoke (New invokedelegate () => {lblinfo. TEXT = "" ;}, null) ;}, null, 600000, true) ;}public void setinfo (string info, color) {lblinfo. invoke (New invokedelegate () => {lblinfo. forecolor = color;}), null); lblinfo. invoke (New invokedelegate () => {lblinfo. TEXT = Info;}), null); threadpool. registerwaitforsingleobject (neversetevt, (OBJ, BOL) =>{ if (lblinfo. ishandlecreated) {lblinfo. invoke (New invokedelegate () => {lblinfo. TEXT = "" ;}), null) ;}, null, 600000, true );}}
When the software is suddenly disabled during debugging,
Lblinfo. Invoke (labchange); the statement goes out first, "You cannot call invoke or begininvoke on the control before creating a window handle ." Error.
The solution is to add an IF (lblinfo. ishandlecreated) before lblinfo. Invoke (labchange );.