Backgroundworker BW = new backgroundworker (); BW. dowork + = (EE, SE) =>{// todo requires asynchronous request operations}; BW. runworkercompleted + = (EW, SW) => {dispatcher. invoke (new action () =>{ <span style = "white-space: pre"> </span> // todo dynamically generated UI}) ;}; BW. runworkerasync ();
Demo:
List <resourceindex> coursewarelist = new list <resourceindex> (); // courseware list <resourceindex> teachingplanlist = new list <resourceindex> (); // teaching plan list <resourceindex> exerciseslist = new list <resourceindex> (); // exercise list <resourceindex> materiallist = new list <resourceindex> (); // material list <resourceindex> reslist = new list <resourceindex> (); string bookcode = ebookcontext. instance. currentbook. indexinfo. code; string unitcode = ebookcontext. instance. currentunit. unitcode; backgroundworker BW = new backgroundworker (); BW. dowork + = (EE, SE) =>{ reslist = searchresource (bookcode, unitcode); foreach (resourceindex resindex in reslist) {Switch (resindex. usage) {Case resourceusage. courseware: coursewarelist. add (resindex); break; Case resourceusage. techingdesign: teachingplanlist. add (resindex); break; Case resourceusage. testquestion: exerciseslist. add (resindex); break; Case resourceusage. teachmaterial: materiallist. add (resindex); break; default: Break ;}}; BW. runworkercompleted + = (EW, SW) => {dispatcher. invoke (new action () => {clearresource (); this. onloading. visibility = visibility. collapsed; If (coursewarelist. count> 0) {resdetailcontainer resc1 = new resdetailcontainer ("courseware", "# ff48b95a", coursewarelist); this. rescontainer. children. add (resc1);} If (teachingplanlist. count> 0) {resdetailcontainer resc2 = new resdetailcontainer ("Teaching Plan", "# fffb5454", teachingplanlist); this. rescontainer. children. add (resc2);} If (exerciseslist. count> 0) {resdetailcontainer resc3 = new resdetailcontainer ("exercises", "# ff3e80da", exerciseslist); this. rescontainer. children. add (resc3);} If (materiallist. count> 0) {resdetailcontainer resc4 = new resdetailcontainer ("clip", "# ffe7b01b", materiallist); this. rescontainer. children. add (resc4);} If (reslist. count = 0) {This. nores. visibility = visibility. visible ;}}) ;}; BW. runworkerasync ();
WPF uses backgroundworker to dynamically load the UI