title: program stuck because of missing thrown events
body: <p>This is the case:  </p>
  
  <p>A business has several sites, each site holds several cameras that take alt of pictures daily (about a thousand pictures each). These pictures are then stored in a folder (one folder for a day) on one computer. </p>
  
  <p>The business own an image analyzing program that gets an "in.xml" file as input and returns an "out.xml" file, for analyzing of one picture. This program  must used and cannot be changed.
  I wrote a UI for that program that runs on that folder and processes each camera from each site, sending pic after pic to that program which runs as a separate process.
  Because this processing is async I have used events at the start and end of every pic's handling, and the same for sites and cameras on sites.</p>
  
  <p>The program run on that business greatly, but sometimes it gets stuck after handling a pic, like it has missed the end_pic_analizing event, and is still waiting for it to be thrown.
  I tried putting a timer for every picture, that moves to the next pic in such cases, but it still got stuck again, acting like is was missing the timer event as well.</p>
  
  <p>This bug happens too many times, even when running almost as single process at that computer, and has got stuck even at the start of the process (happened at the third picture once). this bug doesn't depend on specific pictures either, because it can be stuck at different pics or not be stuck at all, while running repeatedly on the same folder.</p>
  
  <p>Code samples:
  on the Image class:</p>
  
  <pre><code>    static public void image_timer_Elapsed(object sender, ElapsedEventArgs e)
      {
          //stop timer and calculate the how much time left for next check for file. 
          _timer.Stop();
          _timerCount += (int)_timer.Interval;
          int timerSpan = (int)(Daily.duration * 1000) - _timerCount; 
                  //daily.duration is the max duration for seekin the "out.xml" file before quiting.
          if (timerSpan &lt; _timer.Interval) _timer.Interval = timerSpan + 1;
  
          //check for file and analize it.
          String fileName = Daily.OutPath + @"\out.xml";
          ResultHandler.ResultOut output = ResultHandler.GetResult(ref _currentImage);
  
          //if no file found and there is time left wait and check again
          if (output == ResultHandler.ResultOut.FileNotFound &amp;&amp; timerSpan &gt; 0)
          {
              _timer.Start();
          }
          else //file found or time left
          {
               if (MyImage.ImageCheckCompleted != null)
                  MyImage.ImageCheckCompleted(_currentImage); //throw event
                  // the program is probably got stuck here.
          }
  </code></pre>
  
  <p>On camera class:</p>
  
  <pre><code>    static public void Camera_ImageCheckCompleted(MyImage image)
      {
          //if this is not the last image.  (parent as Camera )
          if (image.Id + 1 &lt; image.parent.imageList.Count)
          {
              image.parent.imageList[image.Id + 1].RunCheck(); //check next image
          }
          else
          {
              if (Camera.CameraCheckCompleted != null)
                  Camera.CameraCheckCompleted(image.parent); // throw event
          }
      }
  </code></pre>