c# - Cross thread error, but not using threads -
i keep getting
cross-thread operation not valid: control 'keyholdertxt' accessed thread other thread created on.
on various controls on various forms in project, , have googled , found lot's of responses how access stuff various threads, far know, i'm not using other threads in project, , change hundreds of possible places in code unmanageable.
it never used happen, since added various code seems unrelated. include sample of places errors below, has occurred in many places on solution.
keyholdertxt.text = "keyholders in:\r\n \r\n nibley 1: + keyholders";
or this, better example, can see happends form loading until error:
private void identification_load(object sender, system.eventargs e) { _timer.interval = 1000; _timer.tick += new eventhandler(_timer_tick); _timer.start(); txtidentify.text = string.empty; rightindex = null; sendmessage(action.sendmessage, "place finger on reader."); if (!_sender.openreader()) { this.close(); } if (!_sender.startcaptureasync(this.oncaptured)) { this.close(); } } void _timer_tick(object sender, eventargs e) { this.thetime.text = datetime.now.tostring(); } private void oncaptured(captureresult captureresult) { txtidentify.clear(); //other stuff after cross thread error }
can things not closing datareaders cause kind of error?
i using windows forms application.
i suspect culprit this:
if (!_sender.startcaptureasync(this.oncaptured))
i don't know api you're using, based on name, think callback method (oncaptured
) called on worker thread, not ui thread. need use invoke perform action on ui thread:
private void oncaptured(captureresult captureresult) { if (invokerequired) { invoke(new system.action(() => oncaptured(captureresult))); return; } txtidentify.clear(); // ... }
Comments
Post a Comment