// Fire thread safe event
 private void FireImagerSnapshotEvent(ImagerSnapshotEventArgs snArgs)
 {
     if (this.InvokeRequired)
     {
         this.Invoke(new IntermecImager_SnapshotEvent(FireImagerSnapshotEvent), snArgs);
         return;
     }
     else
     {
         if (this.OnImagerSnapshot != null)
         {
             OnImagerSnapshot(snArgs);
         }
     }
 }
 // Fire thread safe event
 private void FireImagerSnapshotEvent(ImagerSnapshotEventArgs snArgs)
 {
     if (this.InvokeRequired)
     {
         this.Invoke(new IntermecImager_SnapshotEvent(FireImagerSnapshotEvent), snArgs);
         return;
     }
     else
     {
         if (this.OnImagerSnapshot != null)
         {
             OnImagerSnapshot(snArgs);
         }
     }
 }  
        /// <summary>
        /// make a snaphot in a thread
        /// </summary>
        private void DoSnapShot()
        {
            addLog("DoSnapShot: Entering SnapShot thread");
            if (_bTakingSnapShot)
            {
                addLog("DoSnapShot: SnapShot already running");
                return;
            }
            _bTakingSnapShot = true;
            try
            {
                if (File.Exists(_TempFileName))
                {
                    addLog("DoSnapShot: deleting tempfile '" + _TempFileName + "'");
                    File.Delete(_TempFileName);
                }
                else
                {
                    addLog("DoSnapShot: no tempfile '" + _TempFileName + "' to delete");
                }
                addLog("DoSnapShot: invoking '_imager.SnapShot()'...");
                _imager.SnapShot(_TempFileName, Imager.PictureResolutionSize.Full, Imager.FileModeType.JPG); //this line will block for a second or two
                addLog("DoSnapShot: '_imager.SnapShot()' done");
                //wait until the file is ready
                int TryCount = 0;

                addLog("DoSnapShot: waiting for file to be ready...");
                while ((!File.Exists(_TempFileName)) && (TryCount++ < 10)) //high resolution snapshot may take a second or 2
                {
                    System.Threading.Thread.Sleep(500);
                }
                addLog("DoSnapShot: DONE waiting for file to be ready");
                if (File.Exists(_TempFileName))
                {
                    addLog("DoSnapShot: tempfile '" + _TempFileName + "' ready");
                }
                else
                {
                    addLog("DoSnapShot: no tempfile '" + _TempFileName + "' saved by SnapShot!");
                }
                //_imager.VideoRunning = false; //XXX showVideoRunning()
                addLog("DoSnapShot: signaling ImageIsReady()");

                //fire the ready event
                ImagerSnapshotEventArgs snArg = new ImagerSnapshotEventArgs(_TempFileName, SnapshotStatus.Ok);
                addLog("DoSnapShot(): FireImagerSnapshotEvent...");
                FireImagerSnapshotEvent(snArg);
                addLog("DoSnapShot(): calling ShowSnapShot with true");
                showSnapshot(true); //DoSnapShot
                
                //ImageIsReady();
            }
            catch (ThreadAbortException ex)
            {
                addLog("DoSnapShot: ThreadAbortException: " + ex.Message);
            }
            catch (Exception ex)
            {
                addLog("DoSnapShot: Exception: " + ex.Message);
            }
            finally
            {
#if STREAMING_ON
#else
                addLog("Trying to set AimerFlashing...\n" + "Current AimerFlashing=" + _imager.AimerFlashing.ToString());
                _imager.AimerFlashing = Imager.AimerFlashingMode.AlwaysOff;
#endif
            }
            _bTakingSnapShot = false;
            _bLastState = false; //enable next press and hold action
            addLog("DoSnapShot: has been ended.");
        }
        /// <summary>
        /// make a snaphot in a thread
        /// </summary>
        private void DoSnapShot()
        {
            addLog("DoSnapShot: Entering SnapShot thread");
            if (_bTakingSnapShot)
            {
                addLog("DoSnapShot: SnapShot already running");
                return;
            }
            _bTakingSnapShot = true;
            try
            {
                if (File.Exists(_TempFileName))
                {
                    addLog("DoSnapShot: deleting tempfile '" + _TempFileName + "'");
                    File.Delete(_TempFileName);
                }
                else
                {
                    addLog("DoSnapShot: no tempfile '" + _TempFileName + "' to delete");
                }
                addLog("DoSnapShot: invoking '_imager.SnapShot()'...");
                _imager.SnapShot(_TempFileName, Imager.PictureResolutionSize.Full, Imager.FileModeType.JPG); //this line will block for a second or two
                addLog("DoSnapShot: '_imager.SnapShot()' done");
                //wait until the file is ready
                int TryCount = 0;

                addLog("DoSnapShot: waiting for file to be ready...");
                while ((!File.Exists(_TempFileName)) && (TryCount++ < 10)) //high resolution snapshot may take a second or 2
                {
                    System.Threading.Thread.Sleep(500);
                }
                addLog("DoSnapShot: DONE waiting for file to be ready");
                if (File.Exists(_TempFileName))
                {
                    addLog("DoSnapShot: tempfile '" + _TempFileName + "' ready");
                }
                else
                {
                    addLog("DoSnapShot: no tempfile '" + _TempFileName + "' saved by SnapShot!");
                }
                //_imager.VideoRunning = false; //XXX showVideoRunning()
                addLog("DoSnapShot: signaling ImageIsReady()");

                //fire the ready event
                ImagerSnapshotEventArgs snArg = new ImagerSnapshotEventArgs(_TempFileName, SnapshotStatus.Ok);
                addLog("DoSnapShot(): FireImagerSnapshotEvent...");
                FireImagerSnapshotEvent(snArg);
                addLog("DoSnapShot(): calling ShowSnapShot with true");
                showSnapshot(true); //DoSnapShot

                //ImageIsReady();
            }
            catch (ThreadAbortException ex)
            {
                addLog("DoSnapShot: ThreadAbortException: " + ex.Message);
            }
            catch (Exception ex)
            {
                addLog("DoSnapShot: Exception: " + ex.Message);
            }
            finally
            {
#if STREAMING_ON
#else
                addLog("Trying to set AimerFlashing...\n" + "Current AimerFlashing=" + _imager.AimerFlashing.ToString());
                _imager.AimerFlashing = Imager.AimerFlashingMode.AlwaysOff;
#endif
            }
            _bTakingSnapShot = false;
            _bLastState      = false; //enable next press and hold action
            addLog("DoSnapShot: has been ended.");
        }