我构建了一个显示图像的 WPF 控件。现在我想以非常快的速度更改该图像。 我构建了一个 ImageContainer 类,它保存图像并有一个 ChangedEventHandler,它在更改时更新我控件中的图像。
执行的代码如下所示:
videoImageThread = new Thread(
new ThreadStart(
delegate()
{
this.VideoCapture.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
videoImage.Source = VideoImageContainer.Instance.VideoBitmapSourceImage;
}
));
}
));
private void Instance_VideoRefresh()
{
if (VideoImageContainer.Instance.VideoImage != null)
{
lock (videoImageSetLock)
{
videoImageThread.Start();
}
}
}
此代码抛出 System.Reflection.TargetInvocationException,我做错了什么?
最佳答案
在我看来你是在调用一个线程来调用一个线程?!
您是否试过像这样直接调用调度程序上的操作:
private void Instance_VideoRefresh()
{
if (VideoImageContainer.Instance.VideoImage != null)
this.VideoCapture.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
videoImage.Source = VideoImageContainer.Instance.VideoBitmapSourceImage;
}
));
}
关于c# - WPF 中图像更新的 TargetInvocationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2120719/