/// <summary>Connects to the first available GigEVision camera device and runs the acquisition thread.</summary>
        void StartAcquisition()
        {
            connectionStatusLabel.Text = "Connecting...";

            Device = FindFirstAvailableDevice();

            if (Device == null)
            {
                connectionStatusLabel.Text = "Disconnected";
                throw new Exception("Couldn't find any GigEVision camera device");
            }

            DeviceHandle = GenICam.GigEVision_OpenDevice(Device.IpAddress);

            GenICam.GigEVision_StartAcquisition(DeviceHandle.Value, string.Empty, 1);

            acquisitionThread       = new Thread(AcquisitionThread);
            cancellationTokenSource = new CancellationTokenSource();

            acquisitionThread.Start();
        }
        static void RunAcquisition(GigEVision_DeviceDescriptor device)
        {
            var handle = GenICam.GigEVision_OpenDevice(device.IpAddress);

            try
            {
                SetupDevice(handle);
            }
            catch (Exception e)
            {
                ResetDeviceSetup(handle);
                Console.Error.WriteLine("Cannot setup camera device. Device may not be compatible with this demo.");
                Console.Error.WriteLine(e.Message);
                GenICam.GigEVision_CloseHandle(handle);
                return;
            }

            Console.WriteLine("Starting acquisition, close any preview window to stop...");

            // Start acquisition. That will init video stream and activate device, but frames will not be captured until triggered by software command.
            GenICam.GigEVision_StartAcquisition(handle, string.Empty, 1);

            DebugPreviewWindowState window1 = new DebugPreviewWindowState();
            DebugPreviewWindowState window2 = new DebugPreviewWindowState();

            int captureErrors = 0;

            try
            {
                using (Image
                       frameBuffer1 = new Image(),
                       frameBuffer2 = new Image())
                {
                    while (true)
                    {
                        if (!CaptureFramesPair(handle, 8000, 55000, frameBuffer1, frameBuffer2))
                        {
                            // Failed to receive frames.
                            if (++captureErrors >= 3)
                            {
                                // Three capture errors in row
                                throw new TimeoutException("Unable to capture frames.");
                            }
                            else
                            {
                                // Try again from beginning.
                                continue;
                            }
                        }

                        captureErrors = 0;

                        if (!AVL.DebugPreviewShowImage(window1, frameBuffer1) || !AVL.DebugPreviewShowImage(window2, frameBuffer2))
                        {
                            break;
                        }
                    }
                }
            }
            finally
            {
                ResetDeviceSetup(handle);
                GenICam.GigEVision_CloseHandle(handle);
            }
        }