Event stop firing in a loop
I have 2 subs like below, and when I make a loop with开发者_如何学C 1000 iterations and capturePicture() in it. after 700 iterations the event is not raised anymore. Can anyone help me?
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
.NET has a very nice and reliable way to tell you that there's something wrong. But that stops working when you catch Exception and don't do anything to let the user (or you) know what is wrong. Your catch statement is hiding all kinds of serious problems, like OutOfMemory.
Debug + Exceptions, check "Common Language Runtime Exceptions" and run your program.
精彩评论