PLinqInstantFeedbackDataSource Class

A component that can be used as a PLINQ data source for the GridControl in Instant Feedback UI Mode. Can be associated with any IEnumerable source.

Namespace: DevExpress.Xpf.Core.ServerMode

Assembly: DevExpress.Xpf.Core.v20.1.dll

Declaration

public class PLinqInstantFeedbackDataSource :
    PLinqDataSourceBase,
    IDisposable
Public Class PLinqInstantFeedbackDataSource
    Inherits PLinqDataSourceBase
    Implements IDisposable

Remarks

Instant Feedback UI binding mode is an improvement over regular server mode. In server mode, the GridControl loads data in small portions and delegates all data-intensive operations (sorting, grouping, filtering and calculating summaries) to the data server. This is the key to the server mode's high efficiency when working with large volumes of data. The only drawback to using server mode involves data operations when the connection to the server is slow. In this instance, the bound control freezes until the data server completes operations and retrieves results. With Instant Feedback UI binding mode, data operations are performed asynchronously in a background thread, and both the bound control and the application remain highly responsive.

The GridControl can operate on any in-memory IEnumerable data sources using Parallel LINQ (PLINQ), improving performance for data-intensive operations by making full use of all the available processors/cores on the system.

Use PLinqInstantFeedbackDataSource to parallelize data processing on multiple processors in Instant Feedback UI mode. The source collection must implement IEnumerable<T>. It should be specified using the ItemsSourceDataSourceBase.ItemsSource or PLinqInstantFeedbackDataSource.ListSource property.

When using PLinqInstantFeedbackDataSource, the source collection can be dynamically populated by the IListSource.GetList() method or within the PLinqInstantFeedbackDataSource.GetEnumerable event handler. Data objects are loaded in a separate thread, allowing you to perform time-consuming operations (e.g. dynamically create large volumes of data) without the UI freezing. In these instances, you need to ensure thread safety yourself.

NOTE

The PLinqInstantFeedbackDataSource must be disposed of to terminate the processing thread and release all the resources that it owns. This can be done either by calling its PLinqInstantFeedbackDataSource.Dispose method or by executing PLinqInstantFeedbackDataSource.DisposeCommand. For instance, you can execute this command in an MVVM-friendly manner using EventTrigger after a window has been closed (see the example below).

To learn more, see Binding to In-Memory Data Using PLINQ.

Examples

In this demo, the DevExpress Grid Control for WPF operates in Instant Feedback data binding mode on in-memory data. All operations on data (e.g. sorting, groping, filtering, summary calculation, etc.) are performed asynchronously and parallelized on multiple processors. This allows the computing power of your hardware to be utilized to the full extent without UI freezing.See also:

WPF Data Grid Control – PLINQ Data Support

Binding to In-Memory Data Using PLINQ

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;

namespace PLinqDataSource {
    public class PLinqViewModel{

        public PLinqViewModel() {
            ListSource = new OrderDataListSource(1000000);
        }

        public virtual OrderDataListSource ListSource { get; set; }
    }

    public class OrderDataListSource : IListSource {
        List<OrderData> orders;
        int count = 0;
        static object Locker = new object();

        public OrderDataListSource(int count) {
            this.count = count;
        }

        void GenerateOrders() {
            orders = new List<OrderData>(count);
            Random rnd = new Random();
            int customersCount = Data.Customers.Count;
            int productsCount = Data.Products.Count;
            for(int i = 0; i < count; i++) {
                OrderData orderData = new OrderData();
                orderData.OrderId = i + 1;
                orderData.CustomerName = Data.Customers[rnd.Next(customersCount)];
                orderData.OrderDate = DateTime.Today.Subtract(TimeSpan.FromDays(rnd.Next(180)));
                KeyValuePair<string, decimal> product = Data.Products[rnd.Next(productsCount)];
                orderData.ProductName = product.Key;
                orderData.Price = product.Value;
                orderData.Quantity = rnd.Next(200) + 1;
                orders.Add(orderData);
            }
        }
        public IList GetList() {
            if(orders == null) {
                lock(Locker) {
                    if(orders == null) {
                        GenerateOrders();
                    }
                }
            }
            return orders;
        }
        public bool ContainsListCollection {
            get { return false; }
        }
    }

    public class OrderData {
        public int OrderId { get; set; }
        public string CustomerName { get; set; }
        public DateTime OrderDate { get; set; }
        public string ProductName { get; set; }
        public decimal Price { get; set; }
        public int Quantity { get; set; }
    }
}

Inheritance

Object
DispatcherObject
DependencyObject
Visual
UIElement
FrameworkElement
Control
DevExpress.Xpf.Core.DXDesignTimeControl
DevExpress.Xpf.Core.DataSources.SimpleDataSourceBase
ItemsSourceDataSourceBase
DevExpress.Xpf.Core.DataSources.PLinqDataSourceBase
PLinqInstantFeedbackDataSource
See Also