All docs
V21.1
21.1
20.2
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+

IObjectSpaceAsync.ReloadObjectAsync(Object, CancellationToken) Method

Asynchronously reloads the state of the specified persistent object and its aggregated objects from the data store.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v21.1.dll

Declaration

Task<object> ReloadObjectAsync(
    object obj,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

Name Type Description
obj Object

An object that 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.

The specified object can belong to another Object Space. In this case, the current Object Space retrieves the object and then reloads its state.

A CannotReloadPurgedObjectException occurs 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.

See Also