首先我需要说我对WPF和C#都是新手。
应用程序:创建Mandelbrot图像(GUI)
在这种情况下,我的调度程序完美地工作:
private void progressBarRefresh(){
while ((con.Progress) < 99)
{
progressBar1.Dispatcher.Invoke(DispatcherPriority.Send, new Action(delegate
{
progressBar1.Value = con.Progress;
}
));
}
}
使用下面的代码尝试执行此操作时,我收到了以下消息(标题):
bmp = BitmapSource.Create(width, height, 96, 96, pf, null, rawImage, stride);
this.Dispatcher.Invoke(DispatcherPriority.Send, new Action(delegate
{
img.Source = bmp;
ViewBox.Child = img; //vllt am schluss
}
));
我将尝试解释我的程序如何工作。 我创建了一个新线程(因为GUI没有响应),用于计算像素和颜色。在这个线程方法中,我使用Dispatcher在计算准备好后刷新ViewBox中的图像。
如果我不将计算放在单独的线程中,则无法刷新或构建图像。