{"id":5144,"date":"2014-03-30T19:12:34","date_gmt":"2014-03-30T19:12:34","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/event-stop-firing-in-a-loop-collection-of-common-programming-errors\/"},"modified":"2014-03-30T19:12:34","modified_gmt":"2014-03-30T19:12:34","slug":"event-stop-firing-in-a-loop-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/event-stop-firing-in-a-loop-collection-of-common-programming-errors\/","title":{"rendered":"Event stop firing in a loop-Collection of common programming errors"},"content":{"rendered":"<p>I have 2 subs like below, and when I make a loop with 1000 iterations and capturePicture() in it. after 700 iterations the event is not raised anymore. Can anyone help me?<\/p>\n<pre><code> Public Sub capturePicture()\n        Try\n            AddHandler capturePic.FrameEvent2, AddressOf CaptureDone\n            capturePic.GrapImg()\n            Threading.Thread.Sleep(270)\n        Catch ex As Exception\n            RemoveHandler capturePic.FrameEvent2, AddressOf CaptureDone\n        End Try\n  End Sub\n\n\n Private Sub CaptureDone(ByVal e As Bitmap)\n        Try\n            Me.PictureBox1.Image = e\n            PictureBox1.Image.Save(MakeFileNameWithAutoIncrement(MakeFolderNameForCurrentDate(MyFolderName) + \"\\\" + MyTimeStampDatumVrijeme() + \"_\" + Filename4Cam + \"-CAM1(\" + CamEvent + \").JPG\"), System.Drawing.Imaging.ImageFormat.Jpeg)\n            RemoveHandler capturePic.FrameEvent2, AddressOf CaptureDone\n        Catch ex As Exception\n            RemoveHandler capturePic.FrameEvent2, AddressOf CaptureDone\n        End Try \n    End Sub\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have 2 subs like below, and when I make a loop with 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5144","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5144"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5144\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}