XPObjectSpace.ReloadObjectAsync(Object, CancellationToken) Method
Asynchronously reloads the state of the specified persistent object and its aggregated objects from the data store.
Namespace: DevExpress.ExpressApp.Xpo
Assembly: DevExpress.ExpressApp.Xpo.v24.1.dll
NuGet Package: DevExpress.ExpressApp.Xpo
Declaration
Parameters
Name | Type | Description |
---|---|---|
obj | Object | An object which represents the persistent object whose state needs to be reloaded. |
Optional Parameters
Name | Type | Default | Description |
---|---|---|---|
cancellationToken | CancellationToken | null | A CancellationToken object that delivers a cancellation notice to the running operation. |
Returns
Type | Description |
---|---|
Task<Object> | A Task that returns an object. This object is the object specified by the obj parameter after it has been reloaded. |
Remarks
If the specified persistent object is a new object, the ReloadObjectAsync method does nothing. To ensure that the persistent object is not a new object, use the XPObjectSpace.IsNewObject method.
It is not required that the specified object belong to the current Object Space. If it does not belong, it is retrieved by the current Object Space, and then its state is reloaded.
A CannotReloadPurgedObjectException is thrown if the specified persistent object is permanently deleted from the data store.
The following code demonstrates how you can use this method in a View Controller to refresh a List View after a user changes an object on a Detail View and commits these changes. In this scenario, the List View should be read-only.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Win.Editors;
using DevExpress.ExpressApp.Xpo;
using System.Threading;
// ...
public class AsyncUpdateListViewController : ObjectViewController<ListView, DemoTask> {
public AsyncUpdateListViewController() : base() {
SimpleAction updateListViewAction = new SimpleAction(this, "Open assigned contact", "Edit");
updateListViewAction.SelectionDependencyType = SelectionDependencyType.RequireSingleObject;
updateListViewAction.Execute += updateListViewAction_Execute;
}
private void updateListViewAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
object assignedContact = ViewCurrentObject.AssignedTo;
IObjectSpace contactObjectSpace = Application.CreateObjectSpace(assignedContact.GetType());
View contactView = Application.CreateDetailView(contactObjectSpace, contactObjectSpace.GetObject(assignedContact), true);
e.ShowViewParameters.CreatedView = contactView;
contactObjectSpace.Committed += async (s, args) => {
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
await ((XPObjectSpace)ObjectSpace).ReloadObjectAsync(assignedContact, cancellationTokenSource.Token);
if (View.Editor is GridListEditor) {
GridListEditor gridListEditor = (GridListEditor)View.Editor;
gridListEditor.GridView.LayoutChanged();
}
};
}
}
In the current example, the cancellationToken parameter is used for demonstration purposes. You can skip it or use to cancel an asynchronous operation as shown in the CancellationToken topic.