/// <summary>
        /// Start the capture process
        /// </summary>
        public void StartCapture()
        {
            //--Start Capture immediately
            //--create the processing pipeline
            this.capturePipeline = new BackgroundPipeline <CaptureFrame>(Settings.Default.WIIFrequencyHz);

            this.captureStartTime = DateTime.Now;

            this.incrementTrialNumber();

            this.captureFileName = Settings.Default.TrialName;

            this.CaptureTime = TimeSpan.Zero;

            this.dataOutputModule = new OutputModule {
                IsEnabled = true
            };
            this.capturePipeline.Modules.Add(this.dataOutputModule);

            // setup and start the capture
            this.waitingForCapturePipeline = false;

            this.QueueCount = 0;
            this.FrameCount = 0;
            this.capturePipeline.Timer.Tick += Timer_Tick;
            this.capturePipeline.Start();
            this.CaptureInProgress = true;

            Debug.WriteLine("Capture started.");
            SystemMessage.Send("Capture Started - " + Path.Combine(Properties.Settings.Default.SubjectName, this.captureFileName));
        }
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            sensor = KinectSensor.GetDefault();

            frameReader = sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Depth | FrameSourceTypes.Infrared);
            frameReader.MultiSourceFrameArrived += FrameReader_MultiSourceFrameArrived;

            sensor.Open();

            // create a background pipeline and pre-allocate 2 seconds of frames
            pipeline    = new BackgroundPipeline <KinectFrame>(Kinect2Metrics.CameraRate);
            dummyModule = new DummyModule {
                IsEnabled = true
            };
            pipeline.Modules.Add(dummyModule);

            pipeline.Timer.Tick += (sender, args) =>
            {
                FPS     = pipeline.Timer.FPS;
                Elapsed = pipeline.Timer.ElapsedTime;
                BackLog = pipeline.Count;
                var gc1    = GC.CollectionCount(1);
                var gc2    = GC.CollectionCount(2);
                var memory = Process.GetCurrentProcess().PrivateMemorySize64 / 100000000;
                Log += $"{pipeline.Timer.ElapsedTime},{RenderFPS},{FPS},{BackLog},{gc1},{gc2},{memory},{dummyModule.MeanInterval}\n";
            };

            pipeline.FrameStart += (sender, frame) =>
            {
            };

            // return the frame to the pool
            pipeline.FrameComplete += (sender, frame) =>
            {
                frame.Dispose();
            };

            pipeline.QueueComplete += (sender, args) =>
            {
                Console.WriteLine($"{DateTime.Now.ToString("ddMMyyyyhhmmssfffff")}: Queue Complete");
                File.WriteAllText($"report-{DateTime.Now.ToString("ddMMyyyy-hhmmss")}.csv", Log);
            };

            Start = new RelayCommand(StartPipeline, () => !pipeline.Timer.IsRunning);
            Stop  = new RelayCommand(StopPipeline, () => pipeline.Timer.IsRunning);

            stopWatch = new Stopwatch();
            stopWatch.Start();
            RenderFPS = 0;
        }