事件停止在循环中触发

时间:2010-03-19 11:41:26

标签: vb.net

我有2个潜艇,如下所示,当我在其中进行1000次迭代和capturePicture()的循环时。在700次迭代之后,事件不再被引发。 任何人都可以帮助我吗?

 Public Sub capturePicture()
        Try
            AddHandler capturePic.FrameEvent2, AddressOf CaptureDone
            capturePic.GrapImg()
            Threading.Thread.Sleep(270)
        Catch ex As Exception
            RemoveHandler capturePic.FrameEvent2, AddressOf CaptureDone
        End Try
  End Sub


 Private Sub CaptureDone(ByVal e As Bitmap)
        Try
            Me.PictureBox1.Image = e
            PictureBox1.Image.Save(MakeFileNameWithAutoIncrement(MakeFolderNameForCurrentDate(MyFolderName) + "\" + MyTimeStampDatumVrijeme() + "_" + Filename4Cam + "-CAM1(" + CamEvent + ").JPG"), System.Drawing.Imaging.ImageFormat.Jpeg)
            RemoveHandler capturePic.FrameEvent2, AddressOf CaptureDone
        Catch ex As Exception
            RemoveHandler capturePic.FrameEvent2, AddressOf CaptureDone
        End Try 
    End Sub

1 个答案:

答案 0 :(得分:1)

.NET有一个非常漂亮可靠的方式告诉你有什么问题。但是当你捕获Exception并且没有做任何让用户(或你)知道什么是错的时候停止工作。您的catch语句隐藏了各种严重问题,例如OutOfMemory。

Debug + Exceptions,选中“Common Language Runtime Exceptions”并运行程序。