/// <summary> /// Adds a work item to be processed /// </summary> /// <param name="workItem"></param> public void AddWorkItem(FileMoverWorkItem workItem) { lock (workItems) { workItems.Enqueue(workItem); } StartWorkerThread(); }
/// <summary> /// /// </summary> private void Move() { int counter = 0; while (true) { FileMoverWorkItem workItem = null; lock (workItems) { // Get the item if (workItems.Count > 0 && workItems.Peek() != null) { workItem = workItems.Dequeue(); } if (workItem == null) { if (counter == MAX_SLEEP_INTERVALS) { // Max running time so notify that we are not using the thread anymore IsThreadRunning = false; return; } // Keep looking counter++; continue; } } // We have an item so continue working logger.Log("Found item to move."); // Do stuff with the file CopyFile(workItem); logger.Log("Finished moving item"); } }
private void CopyFile(FileMoverWorkItem workItem) { System.IO.File.Copy(workItem.EncodedFilePath, workItem.DestinationFilePath, true); }