[英]Problem using GDI+ with multiple threads (VB.NET)
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. 在tick事件期间引发了一个例外,“该对象目前在其他地方使用”。 Could someone tell me why this happens and how to solve it?
有人能告诉我为什么会这样,以及如何解决它? Thanks.
谢谢。
The Handles timer.Elapsed
indicates a System.Timers.Timer. Handles timer.Elapsed
表示System.Timers.Timer。
Use a System.Windows.Forms.Timer instead and your problem cannot happen anymore. 使用System.Windows.Forms.Timer代替,你的问题不再发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.