Classes to handle the multithreading aspects in applications.


Public classDelegateTask
Executes DelegateTask.CallBack in IDispatcher thread. Usually used in synchronization with GUI thread.
Public classExceptionEventArgs
Event arguments to execute ITask in the IDispatcher's thread
Public classGuiDispatcher
Executes tasks in GUI thread.


Public interfaceIDispatcher
Executes ITask objects with or without blocking the calling thread
Public interfaceITask
Represents a task, that can be executed in the IDispatcher thread


Public delegateDelegateTask..::..CallBack
DelegateTask..::..CallBack delegate that is called in IDispatcher thread. Usually used in synchronization with GUI thread.


All Wpf controls are single-threaded, which means that their methods can be called only in thread where they are running, i.e. the GUI thread. To make sure that application will run safely, you have to synchronize threads. There are two types of synchronization: synchronous and asynchronous. These types are available via Dispatcher.Invoke() and Dispatcher.BeginInvoke() methods accordingly. The main difference between these two methods is that synchronous calls block the calling thread until the end of Dispatcher.Invoke() function call, while asynchronous calls block the thread only for the time while a delegate is added to the queue.

The GridControl is a thread-safe Wpf component. When the grid receives notifications from INotifyPropertyChanged and IBindingList, it performs synchronization with its own thread, thus removing the need to perform synchronization at the data layer and to implement unnecessary references to graphical controls.

 Copy imageCopy
<Window x:Class="WpfApplication1.MainWindow"
   Title="Dapfor Wpf Grid: Threadsafety" Height="200" Width="405">

       <Controls:GridControl Name="dataGrid">
               <Controls:Header ScrollType="Stretch">
                       <Controls:Column Id="Name" Title="Name" />
                       <Controls:Column Id="Price" Title="Price" />

//Simple feed item
public class Feed : INotifyPropertyChanged

//Interaction logic for MainWindow.xaml
public partial class MainWindow : Window
    private readonly BindingList<Feed> _feeds = new BindingList<Feed>();

    public MainWindow()

        //Add some items to the collection
        _feeds.Add(new Feed("Feed1", 10));
        _feeds.Add(new Feed("Feed2", 20));

        ////Bind the grid to the source
        dataGrid.ItemsSource = _feeds;

        //Add a new item in the non-UI thread
            _feeds.Add(new Feed("Feed3", 30));

        //Update item in the non-UI thread
            _feeds[1].Price = 40;