.net - Why doesn't the compiler (or the runtime) do the InvokeRequired pattern for me? -
.net - Why doesn't the compiler (or the runtime) do the InvokeRequired pattern for me? -
why isn't cross-thread ui update safety handled automatically?
to ensure thread-safety when potentially updating ui thread have write if (control.invokerequired()) invoke(..) pattern, or equivalent. runtime observe when i'm calling ui-updating method thread , marshal phone call me? must know when needed because throws exception if seek without necessary precautions.
could compiler apply pattern me on every ui update call? if cause unacceptable overhead, perhaps feature controlled application attribute (the developer apply attribute when writing multi-threaded application in cross-thread ui updates going happen).
i can imagine several potential answers: either it's dumb thought because , or it's impossible/impractical because , or isn't seen add together plenty value justify cost of development.
i can't reply why although inquire if feature worth cost of testing, maintenance documentation etc....when can add together method such as:
public static void updatecontrol(this command ctrl, action<control> action) { if (ctrl.invokerequired) { ctrl.invoke(action,ctrl); } else { action(ctrl); } } you can utilize this.textbox.updatecontrol(c=>c.text="thread safe");
.net winforms thread-safety clr invoke
Comments
Post a Comment