首先我需要说我是 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 不响应)来计算像素和颜色。在这个线程(方法)中,计算准备好后,我正在使用调度程序刷新 ViewBox 中的图像。
当我不将计算放在单独的线程中时,我可以刷新或构建我的图像。