如何使用调度程序加载多个图像 [英] How to use the dispatcher to load multiple images
问题描述
我有与此问题,问题就会得到回答,并且答案似乎也可以(理论上)解决我的问题。但是我不知道如何实现提供的答案。
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.
我试图编写一个名为 LoadNextFive(int startIndex)
的函数,但在该函数的末尾这样称呼自己: this.Dispatcher.BeginInvoke(()=> {LoadNextFive(startIndex + 5);});
但它似乎没有用。我是使用调度程序错误还是执行错误的答案?
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?
-编辑-
我目前仅尝试一次加载1张图像。
--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());
}
}
推荐答案
它似乎当我重写代码时,我忘了重写的一部分。因此仍然是错误。上面的代码工作正常。所以我的问题现在已经过时了。
It seemed that when I rewrote my code I forgot a part to rewrite. Hence still the bug. The code above works fine. So my question is now obsolete.
这篇关于如何使用调度程序加载多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!