我有以下代码,IlegalOperationException
因为我的参数拥有另一个线程。我知道为什么会出现此异常,但我不知道如何解决此问题。
//called on UI thread
public void redraw()
{
new Thread(setPoints).Start(); //calculating new points
}
void setPoints()
{
PointCollection c = new PointCollection();
//calculating points to collection
Task.Factory.StartNew((Action<object>)((p) => { polyline.Points = (PointCollection)p; }), c);
}
编辑:
好的,这里与调度员一致
polyline.Dispatcher.Invoke((Action<PointCollection>)((p) => { polyline.Points = p; }), c);