public void run()
        {
            try
            {
                using (CaptureDeviceDirectShow cam = new CaptureDeviceDirectShow())
                {
                    cam.Start();
                    while (running)
                    {
                        IntPtr ip = cam.GetBitMap();
                        Bitmap bm = new Bitmap(cam.Width, cam.Height, cam.Stride, PixelFormat.Format24bppRgb, ip);
                        bm.RotateFlip(RotateFlipType.RotateNoneFlipY);

                        lock (bm)
                        {
                            if (OnNewFrame != null)
                            {
                                OnNewFrame.Invoke(bm);
                            }
                            bitmap = bm;
                        }
                    }
                }
            }
            catch (Exception ex) { running = false; }
        }
        public void run()
        {
            try
            {
                using (CaptureDeviceDirectShow cam = new CaptureDeviceDirectShow())
                {
                        cam.Start();
                        while (running)
                        {
                            
                            IntPtr ip = cam.GetBitMap();
                            Bitmap bm = new Bitmap(cam.Width, cam.Height, cam.Stride, PixelFormat.Format24bppRgb, ip);
                            bm.RotateFlip(RotateFlipType.RotateNoneFlipY);

                            lock (bm)
                            {
                                if (OnNewFrame != null) OnNewFrame.Invoke(bm);
                                bitmap = bm;
                            }
                        }   
                }
            }
            catch (Exception ex) { running = false;}
        }