I’m trying to fill devexpress GridControl in background (it’s not quick process). I do it like this:
...
CreateGrid();
ShowMessageInsteadOfGridControl;
...
FillGrid(dataGrid, other UI params);
...
Write data in Grid:
private void FillGrid(GridControl data, ...);
{
Task.Factory.StartNew(() =>
{
Application.Current.Dispatcher.Invoke(new Action(() => FillData(gridControl,UIparamns)),
DispatcherPriority.Background);
}).ContinueWith(c => HideUserMessage(UIparamns));
}
When I call FillData, it causes UI freezing. I can’t use usual Task, because Grid filled from UI and I have “The calling thread cannot access this object”.
How to make such dataposting process in background without freezing UI?
The dispatcher invoke call puts everything back on the UI thread, you need to split your operation into parts which can be done in the background and those which really need to be done on the UI-thread, like adding an item, only pass those operations to the dispatcher.
(
DispatcherPriority.Backgroundjust means that other items, with higher priority, will be executed first, this has nothing to do with background threads, every call to the dispatcher of the UI-thread leads to that operation being executed on said UI-thread sooner or later)