/// <summary>
        /// Goes through the work items and begins encoding.
        /// </summary>
        private void ProcessWorkQueueAndEncode()
        {
            int currentCycle = 0;

            while (currentCycle < MAX_CYCLES_FOR_PROCESSING_THREAD)
            {
                HandBrakeWorkItem workItem = null;
                lock (workItems)
                {
                    if (workItems.Count > 0 && workItems.Peek() != null)
                    {
                        workItem = workItems.Dequeue();
                    }
                }

                if (workItem == null)
                {
                    currentCycle++;
                    logger.Log("Didn't find work item. Sleeping");
                    continue;
                }

                // Found a work item. Beginning Encoding and reset cycle count
                currentCycle = 0;
                logger.Log("Found Work Item. Beginning encoding");
                EncodeAndSendToFileMover(workItem);
                logger.Log("Finished Encodeing");
            }
        }
 /// <summary>
 /// Adds the work item to the processor queue and kicks off a worker thread
 /// to begin the processing if a worker thread doesn't exist
 /// </summary>
 /// <param name="workItem"></param>
 private void AddWorkItemInternal(HandBrakeWorkItem workItem)
 {
     lock (workItems)
     {
         workItems.Enqueue(workItem);
     }
     StartWorkerThread();
 }
        /// <summary>
        /// Does the actual encoding work.
        /// </summary>
        /// <param name="workItem">The workItem containing the necessary information to begin encoding</param>
        private void EncodeAndSendToFileMover(HandBrakeWorkItem workItem)
        {
            // Do the encoding
            string encodedFilePath = GetEncodedFilePath(workItem.OriginalFilePath);

            logger.Log("Encoded file path " + encodedFilePath);
            Process process = SetupProcessWithStartInfo(workItem.OriginalFilePath, encodedFilePath);

            process.Start();
            process.WaitForExit();

            // Send the workitem to the filemover to actually move the file
            string destinationPath = GetDestinationPathFromEncodeFile(encodedFilePath, workItem.DestinationDirectory);

            logger.Log("Destination file path" + destinationPath);
            SendWorkItemToFileMover(encodedFilePath, destinationPath);
        }
 /// <summary>
 /// Adds the work item to the processor queue
 /// </summary>
 /// <param name="workItem">The work item to be processed</param>
 public static void AddWorkItem(HandBrakeWorkItem workItem)
 {
     processor.AddWorkItemInternal(workItem);
 }