我已經構建了一個顯示圖像的WPF控件。現在我想以非常快的速度改變這張圖片。 我已經構建了一個ImageContainer類來保存圖像,並有一個ChangedEventHandler,它在更改後更新控件中的圖像。WPF中的圖像更新TargetInvocationException
被執行的代碼看起來是這樣的:
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,我究竟做錯了什麼?
難道是因爲你正在訪問屬於另一個線程調度器? – Andres 2010-01-22 21:52:28
但那不是重點嗎?我不能從控制線程以外的線程更新控件,如果我這樣做,我會得到另一個異常。這就是爲什麼我有這個代碼,它被一些工作者線程調用並鏈接到控制線程 – 2010-01-22 21:56:47
查看異常的InnerException屬性以找到真正的原因。 – 2010-01-22 22:17:57