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.ToListAsync<T>(Object, CancellationToken) Method

Asynchronously enumerates all elements in a collection and saves them to a list.

Namespace: DevExpress.ExpressApp.Xpo

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

Declaration

public Task<List<T>> ToListAsync<T>(
    object collection,
    CancellationToken cancellationToken = null
)
Public Function ToListAsync(Of T)(
    collection As Object,
    cancellationToken As CancellationToken = Nothing
) As Task(Of List(Of T))
public Task<List<T>> ToListAsync<T>(
    object collection,
    CancellationToken cancellationToken = default(CancellationToken)
)
Public Function ToListAsync(Of T)(
    collection As Object,
    cancellationToken As CancellationToken = Nothing
) As Task(Of List(Of T))
public Task<List<T>> ToListAsync<T>(
    object collection,
    CancellationToken cancellationToken = default(CancellationToken)
)
Public Function ToListAsync(Of T)(
    collection As Object,
    cancellationToken As CancellationToken = Nothing
) As Task(Of List(Of T))

Parameters

Name Type Description
collection Object

A collection to be enumerated.

cancellationToken CancellationToken

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

Parameters

Name Type Description
collection Object

A collection to be enumerated.

cancellationToken CancellationToken

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

Parameters

Name Type Description
collection Object

A collection to be enumerated.

cancellationToken CancellationToken

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

Returns

Type Description
Task<List<T>>

A Task that returns a list of objects.

Returns

Type Description
Task<List<T>>

A Task that returns a list of objects.

Returns

Type Description
Task<List<T>>

A Task that returns a list of objects.

Type Parameters

Name Description
T

Type Parameters

Name Description
T

Type Parameters

Name Description
T

Remarks

Use the GetObjectsQuery<T>(Boolean) method to get the XPQuery<T> object to pass it as the ToListAsync<T>(Object, CancellationToken)'s collection parameter. You can also create this object manually.

The following code demonstrates how you can use this method in a WinForms-specific View Controller to add contacts from the Development Department to the task's Contacts collection.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Win;
using DevExpress.ExpressApp.Xpo;
using DevExpress.XtraSplashScreen;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
// ...
public class AsyncTaskContactsController : ObjectViewController<DetailView, DemoTask> {
    public AsyncTaskContactsController() : base() {
        base.OnActivated();
        SimpleAction assignToDepartmentAction = new SimpleAction(this, "Assign to the Dev.Departmant", "Edit");
        assignToDepartmentAction.SelectionDependencyType = SelectionDependencyType.RequireSingleObject;
        assignToDepartmentAction.Execute += assignToDepartmentAction_Execute;
    }
    async private void assignToDepartmentAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
        IOverlaySplashScreenHandle handle = null;
        Control control = Frame.Template as Control;
        WinApplication application = Application as WinApplication;
        CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
        var contacts = from c in ObjectSpace.GetObjectsQuery<Contact>()
                        where c.Department.Title == "Development Department"
                        select c;
        IList<Contact> contactsList = null;
        try {
            if (control != null && control.IsHandleCreated) {
                handle = application.StartOverlayForm(control);
            }
            contactsList = await ((XPObjectSpace)ObjectSpace).ToListAsync<Contact>(contacts, cancellationTokenSource.Token);
            ViewCurrentObject.Contacts.AddRange(contactsList);
        }
        finally {
            if (handle != null) {
                application.StopOverlayForm(handle);
            }
        }
    }
}

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