CameraCar.Controllers.PhotoController.TakingPhotoPreviewWorker C# (CSharp) Method

TakingPhotoPreviewWorker() public static method

public static TakingPhotoPreviewWorker ( object param ) : void
param object
return void
        public static void TakingPhotoPreviewWorker(object param)
        {
            var server = param as HttpServerUtilityBase;
            var imagePath = "/home/pi/ramdisk/photopreview.jpg";

            for (;;)
            {
                var periodUTC = DateTime.UtcNow;

            #if DEBUG
                var photoType = _Counter % 2;
                _Counter++;
                imagePath = server.MapPath(photoType == 0 ?
                    "~/App_Data/penguin.jpg" :
                    "~/App_Data/umiiguana.jpg");
            #else
                // take photo using fswebcam - low resolution/low quality/high compress rate
                lock (_syncFswebcam)
                Process.Start("fswebcam", "-q -r 320 --jpeg 30 --no-banner " + imagePath)
                    .WaitForExit();
            #endif
                var imageBuff = System.IO.File.ReadAllBytes(imagePath);
                if (_AvailableBuffNo == 1)
                    _PhotoPreviewBuff2 = imageBuff;
                else
                    _PhotoPreviewBuff1 = imageBuff;
                lock (_syncBuff)
                {
                    _AvailableBuffNo = _AvailableBuffNo == 1 ? 2 : 1;
                }

                // auto terminate this thread if no access.
                if ((DateTime.UtcNow - _LastAccessUTC).TotalSeconds > 10)
                {
                    lock (_syncThread)
                    {
                        _TakingPhotoPreviewWorkerThread = null;
                        return;
                    }
                }

                Thread.Sleep((int)Math.Max((periodUTC.AddSeconds(1) - DateTime.UtcNow).TotalMilliseconds, 0));
            }
        }