【发布时间】:2011-09-28 08:35:43
【问题描述】:
我在该代码上遇到此异常。 如何解决?
例外:
调用线程不能访问这个 对象,因为不同的线程拥有 它。
代码:
void CamProc_NewTargetPosition(IntPoint Center, System.Drawing.Bitmap image)
{
IntPtr hBitMap = image.GetHbitmap();
BitmapSource bmaps = Imaging.CreateBitmapSourceFromHBitmap(hBitMap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
Dispatcher.BeginInvoke((Action)(() =>
{
labelX.Content = String.Format("X: {0}", Center.X); //OK Working
labelY.Content = String.Format("Y: {0}", Center.Y); //OK Working
pictureBoxMain.Source = bmaps; // THERE IS EXCEPTON
}), DispatcherPriority.Render, null);
}
pictureBoxMain 是 System.Windows.Controls.Image。
【问题讨论】:
标签: c# .net wpf multithreading wpf-controls