All docs
V19.2
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+

XPObjectSpace.GetObjectAsync(Object, CancellationToken) Method

Asynchronously retrieves an object from another Object Space to the current Object Space or gets a wrapped object (i.e., wrapped in XafDataViewRecord or XafInstantFeedbackRecord).

Namespace: DevExpress.ExpressApp.Xpo

Assembly: DevExpress.ExpressApp.Xpo.v19.2.dll

Declaration

public Task<object> GetObjectAsync(
    object obj,
    CancellationToken cancellationToken = null
)
Public Function GetObjectAsync(
    obj As Object,
    cancellationToken As CancellationToken = Nothing
) As Task(Of Object)
public Task<object> GetObjectAsync(
    object obj,
    CancellationToken cancellationToken = default(CancellationToken)
)
Public Function GetObjectAsync(
    obj As Object,
    cancellationToken As CancellationToken = Nothing
) As Task(Of Object)
public Task<object> GetObjectAsync(
    object obj,
    CancellationToken cancellationToken = default(CancellationToken)
)
Public Function GetObjectAsync(
    obj As Object,
    cancellationToken As CancellationToken = Nothing
) As Task(Of Object)

Parameters

Name Type Description
obj Object

An object that represents a template object from another Object Space.

cancellationToken CancellationToken

A CancellationToken object that delivers a cancellation notice to the running operation.

Parameters

Name Type Description
obj Object

An object that represents a template object from another Object Space.

cancellationToken CancellationToken

A CancellationToken object that delivers a cancellation notice to the running operation.

Parameters

Name Type Description
obj Object

An object that represents a template object from another Object Space.

cancellationToken CancellationToken

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 represents the evaluated value.

Returns

Type Description
Task<Object>

A Task that returns an object. This object represents the evaluated value.

Returns

Type Description
Task<Object>

A Task that returns an object. This object represents the evaluated value.

Remarks

This method retrieves the object specified as the obj parameter from the database via the current Object Space's XPObjectSpace.Session. If the passed object is not persistent, it's returned as is.

The following code demonstrates how you can use this method in a View Controller to find and show a Contact the selected DemoTask is assigned to. If this DemoTask is not assigned to any Contact, a Detail View for a new Contact object is shown.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Xpo;
using System;
using System.Threading;
// ...
public class AsyncAssignedToInfoController : ObjectViewController<ListView, DemoTask> {
    View contactView = null;
    public AsyncAssignedToInfoController() : base() {
        SimpleAction showAssignedToInfoAction = new SimpleAction(this, "Assigned contact's info", "Edit");
        showAssignedToInfoAction.SelectionDependencyType = SelectionDependencyType.RequireSingleObject;
        showAssignedToInfoAction.Execute += showAssignedToInfoAction_Execute;
    }
    async private void showAssignedToInfoAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
        CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
        XPObjectSpace contactObjectSpace = (XPObjectSpace)Application.CreateObjectSpace(typeof(Contact));
        contactView = Application.CreateDetailView(contactObjectSpace, "Contact_DetailView", true);
        e.ShowViewParameters.CreatedView = contactView;
        Contact assignedTo = (Contact)ViewCurrentObject.AssignedTo;
            if (assignedTo != null) {
                object obj = await contactObjectSpace.GetObjectAsync(assignedTo, cancellationTokenSource.Token);
                contactView.CurrentObject = obj ?? contactObjectSpace.CreateObject(typeof(Contact));
            }
            else {
                contactView.CurrentObject = contactObjectSpace.CreateObject(typeof(Contact));
            }
        if (contactObjectSpace.IsNewObject(contactView.CurrentObject)) {
            contactObjectSpace.Committed += contactObjectSpace_Committed;
        }
    }
    private void contactObjectSpace_Committed(object sender, EventArgs e) {
        ViewCurrentObject.AssignedTo = ObjectSpace.GetObject(contactView.CurrentObject) as Contact;
    }
}

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