The following problem:
I want to upload files in a program, and the user should be able to make settings.
Because the files are very large, I would like to load them into a new thread so the user can make additional settings in the GUI. (Speed: fast)
- User select file
- Program start a new thread
- the thread is loading the file
- program calls the dispatcher to set the file into the layout
So far so good, step one to three works without problems.
But in step 4, I make a Dispatcher.Invoke.
private void SetNewContent(object newContent)
{
_userControl.Dispatcher.Invoke(
DispatcherPriority.Normal,
new System.Action(
delegate()
{
_userControl.SetContent(newContent);
}
)
};
}
The method _userControl.SetContent is slow. The method takes about 5 seconds for 10,000 pages, which is too long for the user. During this time, the user can not make changes to the GUI settings.
Is there a possibility to prevent it?
You shouldn’t render all content at once. Display only visible content.
If “newContent” is a collection (or can be wrapped into collection), you can bind it to any WPF list controls via “ItemsSource” property – they are virtual, so they will render only visible items.