c# - How to invoke a control within a IF statement -
i have searched quite bit looking how invoke control within if statement awhile , haven't been able find on this. i'm sure i'm missing if show me how great. here short piece of code give idea of problem is.
if(cardpanelopponent.getchildatpoint(new point(i, x)) == null) { opponentcard.location = new point(i, x); cardpanelopponent.invoke(new action(() => cardpanelopponent.controls.add(opponentcard)) break; }
this line taking place in async environment getting cross thread exception. how can run if statement while on different thread ui.
if code running in worker thread you're not allowed call getchildatpoint
or set location
in it. need pass control ui thread.
if(cardpanelopponent.invokerequired) { cardpanelopponent.invoke(new action(() => { if(cardpanelopponent.getchildatpoint(new point(i, x)) == null) { opponentcard.location = new point(i, x); cardpanelopponent.controls.add(opponentcard); } }); }
note: semantics has changed in above code. can't add break statement here. may need correct needs.
Comments
Post a Comment