I want the main thread to wait until the data load operation has completed.
This is part of my ViewModel:
public EmployeeOrdersViewModel() { if (!DesignerProperties.IsInDesignTool) { EntityQuery<Order> queryOrders = _Context.GetOrdersQuery(); LoadOperation<Order> loadOpOrders = _Context.Load(queryOrders); loadOpOrders.Completed += new EventHandler(loadOpOrders_Completed); } } void loadOpOrders_Completed(object sender, EventArgs e) { if (_Context.Orders.Count != 0) { PagedOrders = new PagedCollectionView(_Context.Orders); } } private Employee currentEmployee; public Employee CurrentEmployee { get { return this.currentEmployee; } set { this.currentEmployee = value; // Here I want to wait until loadOpOrders_Completed has executed if (this.CurrentEmployee != null) this.PagedOrders.Filter = o => ((Order)o).EmployeeID == this.CurrentEmployee.EmployeeID; this.PagedOrders.Refresh(); this.NotifyPropertyChanged("CurrentEmployee"); this.NotifyPropertyChanged("PagedOrders"); } }
Answer: 1
Hi Rafael_Soteldo,
In order to make the code executed when loadOpOrders_Completed is inovked, I suggest you move that part of code into loadOpOrders_Completed event handler.
Best Regards,
Answer: 2
I can't. The code is exeuted whenever the current employee is changed, and LoadOpOrders_Completed is executed once at he beginning.
I guess I have to use Thread.Join somehow...
Answer: 3
If you want to load several entitites use the same loadOp_Completed for them
Answer: 4
I don't know if you are already doing it, but if you want the main UI to not allow any user interaction until the operation is complete, you should use a BusyIndicator. But your current View inside a BusyIndicator and bind the BusyIndicator's IsBusy attribute to some IsBusy boolean in your Viewmodel. Before calling the async service, set the IsBusy to true. In the Completed event handler, set the IsBusy to false.
That way, the user won't be able to click or otherwise interact with your UI until you are ready for it.
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog