viperchaos

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

运行C#程序的时候,碰到“Application.Run throws ArgumentException was unhandled”的错误

      在StackOverflowhttp://stackoverflow.com/questions/389551/application-run-throws-argumentexception-was-unhandled看到这样的解释:

      When you use Application.Run(new MyForm());, a message loop is created on the thread using the form object as the main form. It tries to deliver Win32 messages that are coming to the application to their respective objects. However, when you call Dispose() on the form object, you haven't exited the message loop yet. When it tries to deliver the next message to your form object, it fails since it's already disposed and throws the exception. 

      即应用程序在传递消息给程序相应的控件时,你调用了 Dispose()方法,但是你还没退出消息队列,导致传递下一个消息时因为该控件已经Dippose了从而抛出一个异常

      我在MouseMove事件里调用了Dispose()方法就发生了这样的错误

      

   private void MapCoverpictureBox_MouseUp(object sender, MouseEventArgs e)
        {
            if( ShouldPaint == true)
            {
                this.MapCoverpictureBox.BackgroundImage = CoverAreaBitmap;
            }
           
            if( this.MapCoverpictureBox.Image != null)
            {
                this.MapCoverpictureBox.Image.Dispose();
            }
            ShouldPaint = false;
        }

  

  

  

posted on 2012-03-14 22:10  viperchaos  阅读(345)  评论(1编辑  收藏  举报