I have the same problem as stated in this question, and the question is answered and the answer seems also to (theoretically) work in my problem. But I can't figure out how to implement the answer provided.
It suggest that when loading multiple images I batch them and just do a few and then use the dispatcher to start working on the next few.
I tried to write a function called LoadNextFive(int startIndex)
and in the end of the function it just called itself like this: this.Dispatcher.BeginInvoke(() => { LoadNextFive(startIndex + 5); });
but it just didn't seem to work. Am I using the dispatcher wrong or am I implementing the answer wrong?
--EDIT-- I currently tried to just load 1 image at the time.
public void LoadNextImage()
{
if(m_enumerator.MoveNext())
{
if (!m_bitmapSources.ContainsKey(m_enumerator.Current))
{
ZipEntry imageEntry = m_zip.GetEntry(m_enumerator.Current);
using (Stream imageStream = m_zip.GetInputStream(imageEntry))
{
BitmapImage source = new BitmapImage();
source.SetSource(imageStream);
m_bitmapSources.Add(m_enumerator.Current, source);
}
m_dispatcher.BeginInvoke(() => LoadingTemplate.ChangeText(this, "")); //change loadingtext (provides % in future) and it calls this function again
}
else
{
m_dispatcher.BeginInvoke(() => LoadNextImage());
}
}else{
//starts after every image is done loading
LoadPages();
LoadMonths();
OnLoadComplete(new EventArgs());
}
}