Why does my Silverlight BusyIndicator stay invisible after setting IsBusy = true? -
my busyindicator works expected when domaindatasource fetches data. control stays invisible when set isbusy true in code.
i'm using silverlight 4 , toolkit busyindicator. in xaml have bound busyindicator.isbusy property isbusy property of domaindatasource control. busyindicator control wraps main grid (layoutroot) , child controls.
<toolkit:busyindicator isbusy="{binding elementname=labsampledomaindatasource, path=isbusy}" name="busyindicator1"> <grid x:name="layoutroot"> </grid> </toolkit:busyindicator>
the problem busyindicator not show when set busyindicator1 = true; in button click event. idea doing wrong?
the ui updates quite naturally on ui thread. events things button clicks run on ui thread.
in cases property changes , method calls controls result in method being dispatched ui thread. means method invoked not occur until ui thread becomes available execute (and else queued has been executed). isbusy
falls category.
only when code has finished ui thread ui chance update appeareance. should not doing long running tasks in ui thread. in case tie thread own bidding , leave ui starved of 1 thread can use work done.
instead should use backgroundworker
class , heavy work in dowork
event runs on different thread.
mybutton_click(object sender, routedeventargs e) { isbusyindicator1.isbusy = true; var bw = new backgroundworker(); bw.dowork += (s, args) => { //stuff takes time }; bw.runworkercompleted += (s, args) => { isbusyindicator1.isbusy = false; }; bw.runworkerasync(); }
now click event completes allowing ui thread used update ui whilst actual work done on background thread. when completed isbusy cleared.
Comments
Post a Comment