c# - Invoking control from a different thread fails with a cross-threading exception -
in windows forms project have subscribed global keyboard event using win32 api fire event when press win + alt + e, in event handler have code:
_rectangle = new screenboundingrectangle(); _rectangle.location = location; _rectangle.visible = true;
i keep variable rectangle, based on logic, want hide rectangle set visibility false using line of code:
_rectangle.visible = false;
however famous cross threading exception, if try :
this.invoke(new methodinvoker(() => { _rectangle.visible = false; }));
i still cross threading exception!
the _rectangle not have invoke method, there other way around ?
just use visualuiaverify
library , face issue:
download open source , add visiable property of screenboundingrectangle
public bool visible { { return this._visible; } set { this._visible = value; if (value) safenativemethods.showwindow(_form.handle, 8); else { //here invoke _form: this._form.invoke(new methodinvoker(() => { _form.hide(); })); } } }
Comments
Post a Comment