/// <summary>
 /// Delegate that handle the NewFrameImage event handler
 /// </summary>
 /// <param name="e">EventArgs that contains the new image</param>
 protected virtual void OnNewFrameImage(NewFrameImageEventArgs e)
 {
     try
     {
         var handler = NewFrameImage;
         if (handler != null)
         {
             handler(this, e);
         }
     }
     catch (ApplicationException appEx)
     {
         System.Console.WriteLine("Exception in OnNewFrame delegate:\n" + appEx.Message);
     }
     catch (SystemException sysEx)
     {
         System.Console.WriteLine("Exception in OnNwFrame delegate:\n" + sysEx.Message);
     }
 }
        void videoDeviceForCapture_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            try
            {
                int videoDeviceFramesReceived = this.videoDeviceForCapture.FramesReceived;
                if (videoDeviceFramesReceived <= 1)
                {
                    ConsoleBuddy.WriteLineGreen("Number of frames received from last NewFrame event: " + videoDeviceFramesReceived.ToString());
                }
                else
                {
                    ConsoleBuddy.WriteLineRed("Number of frames received from last NewFrame event: " + videoDeviceFramesReceived.ToString());
                }
                this.frameCount = ++this.frameCount;
                DateTime now = DateTime.Now;
                //messages += "Event in WebcamLibrary @ " + now.ToString() + "::" + now.Millisecond.ToString() + ";\t frames received:" + this.frameCount.ToString() + "\r\n";
                System.Drawing.Bitmap copy = (System.Drawing.Bitmap)eventArgs.Frame.Clone();

                /*          this.lastImage = new WebcamImage();
                 *        this.lastImage.image = new Bitmap(copy);
                 *        this.lastImage.timestamp = now;*/
                WebcamImage lastImageObj = new WebcamImage();
                lastImageObj.image      = new Bitmap(copy);
                lastImageObj.timestamp  = now;
                lastImageObj.frameCount = this.frameCount;
                //saveImage(copy, now);
                // 21/11/2016 commented ThreadPool call
                //ThreadPool.QueueUserWorkItem(new WaitCallback(WorkThreadFunction), lastImageObj);
                //
                //this.thread = new Thread(new ThreadStart(WorkThreadFunction));
                //thread.Start();

                NewFrameImageEventArgs e = new NewFrameImageEventArgs(lastImageObj);
                OnNewFrameImage(e);
                copy.Dispose();
            }
            catch (System.NullReferenceException NullEx)
            {
                System.Console.WriteLine("System.NullReferenceException; Message: " + NullEx.Message + "; Source: " + NullEx.Source + "; TargetSite: " + NullEx.TargetSite + ";InnerException: " + NullEx.InnerException + "; Data: " + NullEx.Data + "; HelpLink: " + NullEx.HelpLink + "; StackTrace: " + NullEx.StackTrace);
            }
        }