Silverlight 4 + RIA Service Loads
Is it an acceptable practice to use the same Load Operation to load multiple entities and then binding it to a single event handler asychronously? I'm doing this because I am using a busy indicator and we don't really know which entity gets returned quicker.
Or should I separate the loads into multiple Load Operation / EventHandler pairs?
LoadOperation GetResult; private void LoadinDatagrid() { IsBusy = true; GetResult = DomainContext.Current.Load(GetSomething1Query()); GetResult = DomainContext.Current.Load(GetSomething2Query()); GetResult = DomainContext.Current.Load(GetSomething3Query()); GetResult.Completed += new EventHandler(GetResult_Completed); } void GetResult_Completed(object sender, EventArgs e) { GetSomething1 = DomainContext.Current.Something1; GetSomething2 = DomainContext.Current.Something2; GetSomething3 = DomainContext.Current.Something3; GetResult.Completed -= new EventHandler(GetResult_Completed); IsBusy = false; }
Answers & Comments...
Answer: 1
Answer: 2
Answer: 1
LoadOperation GetResult;
private void LoadinDatagrid() { IsBusy = true; GetResult.Completed += new EventHandler(GetResult_Completed); GetResult = DomainContext.Current.Load(GetSomething1Query()); GetResult = DomainContext.Current.Load(GetSomething2Query()); GetResult = DomainContext.Current.Load(GetSomething3Query()); } void GetResult_Completed(object sender, EventArgs e) { if(e.result!=null){ if(e.result.x=="GetSomething1") GetSomething1 = DomainContext.Current.Something1; else if(e.result.x=="GetSomething2") GetSomething2 = DomainContext.Current.Something2; else if(e.result.x=="GetSomething3") GetSomething3 = DomainContext.Current.Something3; // //Because when returned 1st data then stop eventhandler. //GetResult.Completed -= new EventHandler(GetResult_Completed); // } IsBusy = false; }
by : Ozan Cakırhttp://stackoverflow.com/users/1763013Answer: 2
Try the following:
private int loadCounter; private void LoadinDatagrid() { loadCounter = 3; IsBusy = true; GetResult = DomainContext.Current.Load(GetSomething1Query(), LoadCompleted); GetResult = DomainContext.Current.Load(GetSomething2Query(), LoadCompleted); GetResult = DomainContext.Current.Load(GetSomething3Query(), LoadCompleted); } private void LoadCompleted(LoadOperation result) { Interlocked.Decrement(loadCounter); // Thread save decrementing if(loadCounter == 0) // All queries have been loaded { IsBusy = false; } }
by : Spontifixushttp://stackoverflow.com/users/1521227
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog