c# - Better for loop performance to check radiobuttons -
i have 512 separate radio buttons
, each of them related bool
display.
i made function for loop
uses lots of cpu. there better way this?
for (int k = 0; k < numwords_for_plctohmi_bools * 16; k++) { string sradiobuttonname = "radiobutton_plctohmi_bool" + k.tostring(); radiobutton r = controls.find(sradiobuttonname, true)[0] radiobutton; r.checked = kepwarearrwordtobools_plctohmi[k]; }
you retrieve radiobuttons first, , iterate them afterwards in memory this:
var radiobuttons = this.controls.oftype<radiobutton>(); (int k = 0; k < numwords_for_plctohmi_bools * 16; k++) { string sradiobuttonname = "radiobutton_plctohmi_bool" + k.tostring(); radiobutton r = radiobuttons.single(x => x.name == sradiobuttonname); r.checked = kepwarearrwordtobools_plctohmi[k]; }
this should more efficient.
Comments
Post a Comment