【发布时间】:2012-04-13 18:21:36
【问题描述】:
我要做的是在当前表单的某个位置获取像素颜色。但是,我调用该方法的点是在一个单独的线程中。当我运行应用程序时,我收到一个错误:
跨线程操作无效:从 线程不是创建它的线程。
线程代码:
Thread drawThread;
drawThread = new Thread(drawBikes);
drawBikes 代码:
public void drawBikes()
{
MessageBox.Show("Bike "+bike.color.ToString()+": "+Form1.ActiveForm.GetPixelColor(bike.location.X, bike.location.Y).ToString());
}
这里是 GetPixelColor 方法(在一个单独的静态类中):
public static class ControlExts
{
public static Color GetPixelColor(this Control c, int x, int y)
{
var screenCoords = c.PointToScreen(new Point(x, y));
return Win32.GetPixelColor(screenCoords.X, screenCoords.Y);
}
}
我在哪里调用调用?
【问题讨论】:
-
@L.B 对报告的问题数量表示怀疑,但是.. :)
标签: c# .net multithreading invoke