【发布时间】:2014-03-16 16:37:08
【问题描述】:
我想了解以下为什么会引发异常:
Dim t As New Threading.Thread(Sub()
Dim x As New PictureBox
Invoke(Sub() Controls.Add(x))
x.Location = New Point(1, 0) 'here
End Sub)
t.Start()
注释行抛出异常:
Control accessed from a thread other than the thread it was created on.
但是x是在线程t上创建的,不是吗?
如果我在Controls.Add之前进行分配,它会起作用。 Cotrols.Add 是否会以某种方式更改 x 属于哪个线程?为什么?
动机:
我的表单上有 10-20 个 SWF 播放器控件,所有这些控件都同时播放 flash 电影,如果我将它们全部放在一个线程上,它真的会滞后,所以我需要多线程。
【问题讨论】:
标签: .net multithreading winforms user-controls