title: Synchronizing timer with bitmap refresh
body: <p>In <a href="https://stackoverflow.com/questions/50217280/timer-first-tick-happening-too-fast?noredirect=1#comment87453046_50217280">this question</a> I have been told that I would probably have issues regarding the <code>Timer_Tick</code> event happening during the <code>bitmap</code> change, which would prevent my chart to update. This is, indeed, happening, as my chart seems to update in an erratic way. </p>
  
  <p>Someone suggested that I add some sort of "synchronization" between the <code>Timer</code>and the <code>bitmap</code>refresh. I read a few things online about synchronization in C#, as I have never used such a thing, but nothing that really related to my concern.</p>
  
  <p>I have not the slightest clue as to how I could implement this kind of behaviour in my code. Is someone able to help me here ? The code related to this question is featured in the <a href="https://stackoverflow.com/questions/50217280/timer-first-tick-happening-too-fast?noredirect=1#comment87453046_50217280">linked question</a>, in case you want to look at it.</p>
  
  <p>Thanks</p>
  
  <p>EDIT : Here is a more detailled version of the code that starts the acquisition from the camera : </p>
  
  <pre><code>private void BtAcquisitionLiveCam_Click(object sender, EventArgs e)
      {
          // Getting the list of plugged cameras
          CameraCollection cameras = vimba.Cameras;
  
          //Starting the chosen camera
          string id = cameras[0].Id;
          mycamera = vimba.OpenCameraByID(id, VmbAccessModeType.VmbAccessModeFull);
  
          // Preparing image acquisition and starting it
          Frame[] frameArray = new Frame[3];
          Feature featurePayloadSize = null;
          long payloadSize;
          featurePayloadSize = features["PayloadSize"];
          payloadSize = featurePayloadSize.IntValue;
  
          for (int index = 0; index &lt; frameArray.Length; ++index)
          {
              frameArray[index] = new Frame(payloadSize);
              mycamera.AnnounceFrame(frameArray[index]);
          }
  
          for (int index = 0; index &lt; frameArray.Length; ++index)
          {
              mycamera.QueueFrame(frameArray[index]);
          }
  
          this.m_Acquiring = true;
          mycamera.OnFrameReceived += new Camera.OnFrameReceivedHandler(this.OnFrameReceived);
          mycamera.StartContinuousImageAcquisition(1);
      }
  
      //Setting timer for histogram update
      Timer histTimer = new Timer();
      histTimer.Interval = 500; // specify interval time as you want
      histTimer.Tick += new EventHandler(histTimer_Tick);
      histTimer.Start();
  }
  </code></pre>
  
  <p>The OnFrameReceived event is the only event that's trigered by the camera. I previously tried to make my histogram upadte on every iteration of it (by placing it's code directly in the event code), but to no avail, as I was probably limited by the computation time required.</p>