使用 GDI 时出现问题多线程 (VB.NET)
我认为最好只是复制并粘贴代码(这非常简单)。
Private Sub Main() Handles MyBase.Shown
timer.Interval = 10
timer.Enabled = True
End Sub
Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
e.Graphics.DrawImage(image, 0, 0)
End Sub
Private Sub tick() Handles timer.Elapsed
Using g = Graphics.FromImage(image)
g.Clear(Color.Transparent)
g.DrawLine(Pens.Red, 0 + i, 0 + i, Me.Width - i, Me.Height - i)
End Using
Me.Invalidate()
End Sub
在勾选事件期间引发异常“该对象当前正在其他地方使用”。有人可以告诉我为什么会发生这种情况以及如何解决它吗?谢谢。
I think it would be best if I just copy and pasted the code (it's very trivial).
Private Sub Main() Handles MyBase.Shown
timer.Interval = 10
timer.Enabled = True
End Sub
Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
e.Graphics.DrawImage(image, 0, 0)
End Sub
Private Sub tick() Handles timer.Elapsed
Using g = Graphics.FromImage(image)
g.Clear(Color.Transparent)
g.DrawLine(Pens.Red, 0 + i, 0 + i, Me.Width - i, Me.Height - i)
End Using
Me.Invalidate()
End Sub
An exception, "The object is currently in use elsewhere", is raised during the tick event. Could someone tell me why this happens and how to solve it? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Handles timer.Elapsed
表示 System.Timers.Timer。使用 System.Windows.Forms.Timer 代替,您的问题就不会再发生了。
The
Handles timer.Elapsed
indicates a System.Timers.Timer.Use a System.Windows.Forms.Timer instead and your problem cannot happen anymore.