public new void Dispose()
        {
            addLog("Dispose() called...");
            _continueWait = false; //signal thread to stop
            Thread.Sleep(100);
            SystemEvent waitEvent = new SystemEvent("EndWaitLoop52", false, false);

            waitEvent.PulseEvent();
            Thread.Sleep(100);

#if STREAMING_ON
            //kill SnapShot Thread
            if (snapshotThread != null)
            {
                int iCount = 0;
                while (iCount < 10 && _bSnapShotThreadRunning)
                {
                    Thread.Sleep(500);
                    iCount++;
                }
                if (_bSnapShotThreadRunning)
                {
                    if (snapshotThread != null)
                    {
                        snapshotThread.Abort();
                    }
                }
            }
#endif
            Thread.Sleep(100);

            if (_imager != null)
            {
                //restore AimerFlashing mode
                _imager.AimerFlashing = Imager.AimerFlashingMode.Auto;
                _imager.LightGoal     = 128;
                _imager.VideoRunning  = false;
                _imager.Dispose();
                _imager = null;
            }
            //enable HW Trigger of Scanner
            //S9CconfigClass.S9Cconfig.HWTrigger.setHWTrigger(true); //removed as problems with ADCComInterface
            YetAnotherHelperClass.setHWTrigger(true);
            restoreKey();

            Cursor.Current = Cursors.Default;
            // base.Dispose(); do not use!!
            addLog("...Dispose() finished");
        }
        public IntermecImagerControl2()
        {
            InitializeComponent();
            //setup imager
            try
            {
                //disable HW Trigger of Scanner
                //S9CconfigClass.S9Cconfig.HWTrigger.setHWTrigger(false); //removed as problems with ADCComInterface
                YetAnotherHelperClass.setHWTrigger(false);

                _imager = new Imager(ImagerPreview, Imager.PictureResolutionSize.Quarter);
                _imager.ImagerMode = Imager.ImagerModeType.Imaging;
                _imager.OnScreenLogo = Imager.OnScreenLogoType.Off;

                if (_imager.ImageConditioningAvailable)
                {

                    //change according to Bo Shang, eMail of 22. Juli 2011 02:16
                    _imager.ImageConditioning.ContrastEnhancement = ImageConditioning.ContrastEnhancementValue.Photo;
                    _imager.ImageConditioning.TextEnhancement = ImageConditioning.TextEnhancementValue.None;
                    _imager.ImageConditioning.ImageRotation = ImageConditioning.ImageRotationValue.None;
                    //use the following to enhance streaming performance
                    _imager.ImageConditioning.Subsampling = ImageConditioning.SubsamplingValue.OneOfEight;// ImageConditioning.SubsamplingValue.None;
                    _imager.ImageConditioning.NoiseReduction = 0;

                    //DO NOT USE other than NONE, a bug will then show a blank preview video
                    _imager.ImageConditioning.ImageLightingCorrection = ImageConditioning.ImageLightingCorrectionValue.None;// Enabled;// None;
                    _imager.ImageConditioning.Brightness = 20;
                    //the following setting changes the image very strong (B&W to Gray)
                    _imager.ImageConditioning.ColorMode = ImageConditioning.ColorModeValue.None;// None;

                    //this for the preview AND changes the way of the snapshot
                    _imager.ImageConditioning.ColorModeBrightnessThreshold = ImageConditioning.ColorModeBrightnessThresholdValue.VeryDark;
                    _imager.ImageConditioning.OutputCompression = ImageConditioning.OutputCompressionValue.Bitmap;
                    _imager.ImageConditioning.OutputCompressionQuality = 100;

                    //shutoff laser illumination, gives system exception "Invalid Illumination Status value"
                    //addLog("Trying to set Illumination...\n" + "Current IlluminationAimerStatus=" + _imager.IlluminationAimerStatus.ToString());
                    //_imager.IlluminationAimerStatus = Imager.IlluminationAimerActivationType.IlluminationOnly;

                    addLog("Trying to set AimerFlashing...\n" + "Current AimerFlashing=" + _imager.AimerFlashing.ToString());
                    _imager.AimerFlashing = Imager.AimerFlashingMode.AlwaysOff;

                    //_imager.IllumFlashing = Imager.IllumFlashingMode.Auto;

                    addLog("Trying to set LightGoal...\n" + "Current LightGoal=" + _imager.LightGoal.ToString());
                    _imager.LightGoal = 150;

                    //the following two settings are unsupported on current test device and OS
                    //addLog("Trying to set SetAimerOn...\n" + "Current SetAimerOn=" + _imager.SetAimerOn.ToString());
                    //_imager.SetAimerOn = false;
                    //addLog("Trying to set SetIllumOn...\n" + "Current SetIllumOn=" + _imager.SetIllumOn.ToString());
                    //_imager.SetIllumOn = false;

                    //change defaults for snapshot file using explicit settings
                    _imager.SnapShotConditioning.Brightness = 20;
                    _imager.SnapShotConditioning.ColorConversion = ImageConditioning.ColorConversionValue.Grayscale;
                    _imager.SnapShotConditioning.ColorMode = ImageConditioning.ColorModeValue.None;
                    _imager.SnapShotConditioning.ColorModeBrightnessThreshold = ImageConditioning.ColorModeBrightnessThresholdValue.Normal;
                    _imager.SnapShotConditioning.ContrastEnhancement = ImageConditioning.ContrastEnhancementValue.Photo;
                    _imager.SnapShotConditioning.ImageLightingCorrection = ImageConditioning.ImageLightingCorrectionValue.None;
                    _imager.SnapShotConditioning.ImageRotation = ImageConditioning.ImageRotationValue.None;
                    _imager.SnapShotConditioning.NoiseReduction = 0;
                    _imager.SnapShotConditioning.OutputCompression = ImageConditioning.OutputCompressionValue.Jpeg;
                    _imager.SnapShotConditioning.OutputCompressionQuality = 80;
                    _imager.SnapShotConditioning.Subsampling = ImageConditioning.SubsamplingValue.None;
                    _imager.SnapShotConditioning.TextEnhancement = ImageConditioning.TextEnhancementValue.None;
                    

                    //change defaults for snapshot file by using already defined ImageConditioning values
                    //disagreed by Bo Shang 3. aug. 2011
                    /*
                    _imager.SnapShotConditioning = _imager.ImageConditioning;
                    _imager.SnapShotConditioning.OutputCompression = ImageConditioning.OutputCompressionValue.Jpeg;
                    _imager.SnapShotConditioning.OutputCompressionQuality = 80;
                    */
                    //_imager.SnapShotConditioning.Brightness = 20;
                    //_imager.SnapShotConditioning.ColorMode = ImageConditioning.ColorModeValue.None;
                    addLog("================== Imager ===================\n");
                    addLog(ImageHelper.dumpConditioningValues(_imager.ImageConditioning));
                    addLog("================= Snapshot ==================\n");
                    addLog(ImageHelper.dumpConditioningValues(_imager.SnapShotConditioning));

                }
                else
                {
                    _imager.EnhanceContrast = true;
                }

                //remap scan button key to new events
                ITCTools.KeyBoard.mapKey();
                //start the scan button watch thread
                addLog("IntermecImagerControl-ImagerInit: starting named event watch thread...");
                waitThread = new System.Threading.Thread(waitLoop);
                waitThread.Start();

#if NO_SNAPSHOT_THREAD
#else
                this.OnImagerSnapshot += new IntermecImager_SnapshotEvent(IntermecImagerControl2_OnImagerSnapshot);
#endif
#if STREAMING_ON
                _imager.VideoRunning = true;
                //show hide the right pictureboxes
                ImagerPreview.Visible = false;
                ImagerSnapshot.Image = null;
                ImagerSnapshot.Refresh();
                ImagerSnapshot.Visible = true;
                addLog("IntermecImagerControl2(): calling ShowSnapShot with true");
                //showSnapshot(true); // we start with no streaming View
#else
                //start with streaming=off
                showSnapshot(false);
#endif

            }
            catch (Intermec.DataCollection.ImagerException ex)
            {
                addLog("ImagerException in ImagerInit. Is the runtime 'DC_NET.CAB'/ITCimager.dll installed?\n" + ex.Message);
            }
            catch (Exception ex)
            {
                addLog("Exception in ImagerInit. Is the runtime 'DC_NET.CAB'/ITCimager.dll installed?\n" + ex.Message);
            }
            if (_imager == null)
            {
                addLog("IntermecImagerControl: Imager init FAILED");
                throw new System.IO.FileNotFoundException("IntermecImagerControl: Imager init FAILED - Is the runtime 'DC_NET.CAB'/ITCimager.dll installed?\n");
            }

        }
        public new void Dispose()
        {
            addLog("Dispose() called...");
            _continueWait = false; //signal thread to stop
            Thread.Sleep(100);
            SystemEvent waitEvent = new SystemEvent("EndWaitLoop52", false, false);
            waitEvent.PulseEvent();
            Thread.Sleep(100);

#if STREAMING_ON
            //kill SnapShot Thread
            if (snapshotThread != null)
            {
                snapshotThread.Abort();
            }
#endif
            Thread.Sleep(100);

            if (_imager != null)
            {
                //restore AimerFlashing mode
                _imager.AimerFlashing = Imager.AimerFlashingMode.Auto;
                _imager.LightGoal = 128;
                _imager.VideoRunning = false;
                _imager.Dispose();
                _imager = null;
            }
            //enable HW Trigger of Scanner
            //S9CconfigClass.S9Cconfig.HWTrigger.setHWTrigger(true); //removed as problems with ADCComInterface
            YetAnotherHelperClass.setHWTrigger(true);
            ITCTools.KeyBoard.restoreKey();

            Cursor.Current = Cursors.Default;
            // base.Dispose(); do not use!!
            addLog("...Dispose() finished");
        }
        public IntermecImagerControl2()
        {
            InitializeComponent();
            //setup imager
            try
            {
                //disable HW Trigger of Scanner
                //S9CconfigClass.S9Cconfig.HWTrigger.setHWTrigger(false); //removed as problems with ADCComInterface
                YetAnotherHelperClass.setHWTrigger(false);

                _imager              = new Imager(ImagerPreview, Imager.PictureResolutionSize.Quarter);
                _imager.ImagerMode   = Imager.ImagerModeType.Imaging;
                _imager.OnScreenLogo = Imager.OnScreenLogoType.Off;

                if (_imager.ImageConditioningAvailable)
                {
                    //change according to Bo Shang, eMail of 22. Juli 2011 02:16
                    _imager.ImageConditioning.ContrastEnhancement = ImageConditioning.ContrastEnhancementValue.Photo;
                    _imager.ImageConditioning.TextEnhancement     = ImageConditioning.TextEnhancementValue.None;
                    _imager.ImageConditioning.ImageRotation       = ImageConditioning.ImageRotationValue.None;
                    //use the following to enhance streaming performance
                    _imager.ImageConditioning.Subsampling    = ImageConditioning.SubsamplingValue.OneOfEight;// ImageConditioning.SubsamplingValue.None;
                    _imager.ImageConditioning.NoiseReduction = 0;

                    //DO NOT USE other than NONE, a bug will then show a blank preview video
                    _imager.ImageConditioning.ImageLightingCorrection = ImageConditioning.ImageLightingCorrectionValue.None;// Enabled;// None;
                    _imager.ImageConditioning.Brightness = 20;
                    //the following setting changes the image very strong (B&W to Gray)
                    _imager.ImageConditioning.ColorMode = ImageConditioning.ColorModeValue.None;// None;

                    //this for the preview AND changes the way of the snapshot
                    _imager.ImageConditioning.ColorModeBrightnessThreshold = ImageConditioning.ColorModeBrightnessThresholdValue.VeryDark;
                    _imager.ImageConditioning.OutputCompression            = ImageConditioning.OutputCompressionValue.Bitmap;
                    _imager.ImageConditioning.OutputCompressionQuality     = 100;

                    //shutoff laser illumination, gives system exception "Invalid Illumination Status value"
                    //addLog("Trying to set Illumination...\n" + "Current IlluminationAimerStatus=" + _imager.IlluminationAimerStatus.ToString());
                    //_imager.IlluminationAimerStatus = Imager.IlluminationAimerActivationType.IlluminationOnly;

                    addLog("Trying to set AimerFlashing...\n" + "Current AimerFlashing=" + _imager.AimerFlashing.ToString());
                    _imager.AimerFlashing = Imager.AimerFlashingMode.AlwaysOff;

                    //_imager.IllumFlashing = Imager.IllumFlashingMode.Auto;

                    addLog("Trying to set LightGoal...\n" + "Current LightGoal=" + _imager.LightGoal.ToString());
                    _imager.LightGoal = 150;

                    //the following two settings are unsupported on current test device and OS
                    //addLog("Trying to set SetAimerOn...\n" + "Current SetAimerOn=" + _imager.SetAimerOn.ToString());
                    //_imager.SetAimerOn = false;
                    //addLog("Trying to set SetIllumOn...\n" + "Current SetIllumOn=" + _imager.SetIllumOn.ToString());
                    //_imager.SetIllumOn = false;

                    //change defaults for snapshot file using explicit settings
                    _imager.SnapShotConditioning.Brightness      = 20;
                    _imager.SnapShotConditioning.ColorConversion = ImageConditioning.ColorConversionValue.Grayscale;
                    _imager.SnapShotConditioning.ColorMode       = ImageConditioning.ColorModeValue.None;
                    _imager.SnapShotConditioning.ColorModeBrightnessThreshold = ImageConditioning.ColorModeBrightnessThresholdValue.Normal;
                    _imager.SnapShotConditioning.ContrastEnhancement          = ImageConditioning.ContrastEnhancementValue.Photo;
                    _imager.SnapShotConditioning.ImageLightingCorrection      = ImageConditioning.ImageLightingCorrectionValue.None;
                    _imager.SnapShotConditioning.ImageRotation            = ImageConditioning.ImageRotationValue.None;
                    _imager.SnapShotConditioning.NoiseReduction           = 0;
                    _imager.SnapShotConditioning.OutputCompression        = ImageConditioning.OutputCompressionValue.Jpeg;
                    _imager.SnapShotConditioning.OutputCompressionQuality = 80;
                    _imager.SnapShotConditioning.Subsampling     = ImageConditioning.SubsamplingValue.None;
                    _imager.SnapShotConditioning.TextEnhancement = ImageConditioning.TextEnhancementValue.None;


                    //change defaults for snapshot file by using already defined ImageConditioning values
                    //disagreed by Bo Shang 3. aug. 2011

                    /*
                     * _imager.SnapShotConditioning = _imager.ImageConditioning;
                     * _imager.SnapShotConditioning.OutputCompression = ImageConditioning.OutputCompressionValue.Jpeg;
                     * _imager.SnapShotConditioning.OutputCompressionQuality = 80;
                     */
                    //_imager.SnapShotConditioning.Brightness = 20;
                    //_imager.SnapShotConditioning.ColorMode = ImageConditioning.ColorModeValue.None;
                    addLog("================== Imager ===================\n");
                    addLog(ImageHelper.dumpConditioningValues(_imager.ImageConditioning));
                    addLog("================= Snapshot ==================\n");
                    addLog(ImageHelper.dumpConditioningValues(_imager.SnapShotConditioning));
                }
                else
                {
                    _imager.EnhanceContrast = true;
                }

                //remap scan button key to new events
                ITCTools.KeyBoard.mapKey();
                //start the scan button watch thread
                addLog("IntermecImagerControl-ImagerInit: starting named event watch thread...");
                waitThread = new System.Threading.Thread(waitLoop);
                waitThread.Start();

#if NO_SNAPSHOT_THREAD
#else
                this.OnImagerSnapshot += new IntermecImager_SnapshotEvent(IntermecImagerControl2_OnImagerSnapshot);
#endif
#if STREAMING_ON
                _imager.VideoRunning = true;
                //show hide the right pictureboxes
                ImagerPreview.Visible = false;
                ImagerSnapshot.Image  = null;
                ImagerSnapshot.Refresh();
                ImagerSnapshot.Visible = true;
                addLog("IntermecImagerControl2(): calling ShowSnapShot with true");
                //showSnapshot(true); // we start with no streaming View
#else
                //start with streaming=off
                showSnapshot(false);
#endif
            }
            catch (Intermec.DataCollection.ImagerException ex)
            {
                addLog("ImagerException in ImagerInit. Is the runtime 'DC_NET.CAB'/ITCimager.dll installed?\n" + ex.Message);
            }
            catch (Exception ex)
            {
                addLog("Exception in ImagerInit. Is the runtime 'DC_NET.CAB'/ITCimager.dll installed?\n" + ex.Message);
            }
            if (_imager == null)
            {
                addLog("IntermecImagerControl: Imager init FAILED");
                throw new System.IO.FileNotFoundException("IntermecImagerControl: Imager init FAILED - Is the runtime 'DC_NET.CAB'/ITCimager.dll installed?\n");
            }
        }