System.InvalidOperationException:Object目前正在其他地方使用。在编写蛇游戏

时间:2014-01-20 18:52:42

标签: c# forms exception object graphics

所以我过去编写了一个蛇游戏,出了点问题。我所知道的是,在我尝试玩的过程中,当蛇在屏幕上的某个位置时,它会引发异常:

System.InvalidOperationException: Object is currently in use elsewhere.
    at System.Drawing.Image.get_Height()
    at System.Drawing.Image.get_Size()
    at System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode(PictureBoxSizeMode mode)
    at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
    at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
    at System.Windows.Forms.Control.WmPaint(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

当我调试它时,标记下面的一段代码:

for (int i = 1; i < myS.organs.Count; i++)
    if (squares[myS.organs[i].Y, myS.organs[i].X].Image == null)
    {
        **squares[myS.organs[i].Y, myS.organs[i].X].Image = b;**//this is the line it marks.
    }

我知道这些信息不够,但我得到的只是它。我真的无法弄清楚这个问题的来源,所以如果你需要更多的信息来指导我,我可以给你......谢谢!

0 个答案:

没有答案