/// <summary>
        ///     Method that can be used in a single thread.
        ///     Based on the printJob given, build a PrintJobData object,
        ///     run automations on the PrintJobData based on BlockedUsers and autoDelete.
        ///     When finished automating, add it to a list of CurrentPrintJobs.
        /// </summary>
        /// <param name="printJob"> A managementObject of type Win32_PrintJob. </param>
        private void ThreadedPrintJob(ManagementObject printJob)
        {
            var logBuilder = "";
            var pages = int.Parse(printJob.Properties ["TotalPages"].Value.ToString());
            var jobDataBuilder = new PrintJobData {
                                                      JobId = int.Parse(printJob.Properties ["JobId"].Value.ToString()),
                                                      Size = int.Parse(printJob.Properties ["Size"].Value.ToString()),
                                                      Pages = pages == 0 ? 1 : pages,
                                                      Status = GetCurrentStatus(printJob.Properties ["StatusMask"].Value.ToString(), true),
                                                      TimeStarted = printJob.Properties ["TimeSubmitted"].Value.ToString(),
                                                      User = printJob.Properties ["Owner"].Value.ToString(),
                                                      DocumentName = printJob.Properties ["Document"].Value.ToString(),
                                                      MachineName = printJob.Properties ["HostPrintQueue"].Value.ToString()
                                                  };
            //Set the proper time to a legible fasion.
            var hour = Convert.ToInt32(jobDataBuilder.TimeStarted.Substring(8, 2));
            var isPm = hour%13 < hour;
            hour = isPm ? hour%13 + 1 : hour;
            var min = jobDataBuilder.TimeStarted.Substring(10, 2);
            var sec = jobDataBuilder.TimeStarted.Substring(12, 2);
            var day = jobDataBuilder.TimeStarted.Substring(6, 2);
            var mon = jobDataBuilder.TimeStarted.Substring(4, 2);
            var year = jobDataBuilder.TimeStarted.Substring(0, 4);
            jobDataBuilder.TimeStarted = hour + ":" + min + ":" + sec + " " + (isPm ? "PM" : "AM") + " - (" + mon + "/" + day + "/" + year + ")";

            var userAllocatedPages = CheckBlockedList(jobDataBuilder);
            //Check for autoDelete.
            if (jobDataBuilder.Pages > PrinterWindow.DeletePrintLimit || userAllocatedPages > PrinterWindow.DeletePrintLimit) {
                try {
                    printJob.Properties ["StatusMask"].Value = (uint) printJob.Properties ["StatusMask"].Value + PrintJobFlags.AutoDelete;
                    jobDataBuilder.Status = GetCurrentStatus(printJob.Properties ["StatusMask"].Value.ToString(), true);
                    printJob.Delete();
                    DeleteBlockedJob(jobDataBuilder);
                    logBuilder += "\r\n   Job deleted: " + jobDataBuilder.JobId + " : " + jobDataBuilder.MachineName;
                }
                catch (Exception ex) {
                    logBuilder += "\r\nError on auto delete for job " + jobDataBuilder.JobId + ": " + ex.Message +
                                  "\r\n\r\n" + ex.StackTrace;
                }
            }
            //Check for autoPause.
            else if (jobDataBuilder.Pages > PrinterWindow.PausePrintLimit || userAllocatedPages > PrinterWindow.PausePrintLimit) {
                try {
                    printJob.InvokeMethod("Pause", null);
                    printJob.Properties ["StatusMask"].Value = (uint) printJob.Properties ["StatusMask"].Value + PrintJobFlags.AutoPause - PrintJobFlags.Paused;
                    jobDataBuilder.Status = GetCurrentStatus(printJob.Properties["StatusMask"].Value.ToString(), true);
                    logBuilder += "\r\n   Job paused: " + jobDataBuilder.JobId + " : " + jobDataBuilder.MachineName;
                }
                catch (Exception ex) {
                    logBuilder += "\r\nError on auto pause for job " + jobDataBuilder.JobId + ": " + ex.Message +
                                  "\r\n\r\n" + ex.StackTrace;
                }
            }
            logBuilder += "\r\n Job allowed: " + jobDataBuilder.JobId + " : " + jobDataBuilder.MachineName;
            LogManager.AppendLog(logBuilder);

            CheckPrintHistory(jobDataBuilder);
            lock (CurrentPrintJobs)
                CurrentPrintJobs.Add(jobDataBuilder);
        }
 /// <summary>
 ///     Search the history. If the job is new, add it to the list. If not, see if the old history is updateable.
 /// </summary>
 /// <param name="newJob">PrintJobData of the job that needs to be checked for history references.</param>
 private void CheckPrintHistory(PrintJobData newJob)
 {
     lock (CollectedHistory) {
         var oldJobId = false;
         foreach (var oldData in CollectedHistory.Where(oldData => oldData.JobId == newJob.JobId)) {
             oldJobId = true;
             oldData.CheckFilledData(newJob);
         }
         if (!oldJobId) CollectedHistory.Add(newJob);
     }
 }
 /// <summary>
 ///     Delete the selected job from the blocked users list. This removes that job's allocation. Keeps previous blocked
 ///     allocation.
 /// </summary>
 /// <param name="deleteJob">PrintJobData that needs to be cleared from the list.</param>
 private void DeleteBlockedJob(PrintJobData deleteJob)
 {
     foreach (var data in BlockedUsers) {
         if (data.MachineName == deleteJob.MachineName)
             data.DeleteJob(deleteJob);
     }
 }
 /// <summary>
 ///     Search the block list. If the job is new, add it to the list. If not, update the user's current record.
 /// </summary>
 /// <param name="newJob">PrintJobData of the job that needs to be added to the block list.</param>
 /// <returns>A boolean if the job needs to be paused or not.</returns>
 private int CheckBlockedList(PrintJobData newJob)
 {
     var oldUserName = false;
     foreach (var oldData in BlockedUsers.Where(oldData => (oldData.MachineName == newJob.MachineName) && (oldData.UserName == newJob.User))) {
         oldUserName = true;
         oldData.UpdateBlocker(newJob);
     }
     if (!oldUserName) {
         BlockedUsers.Add(new PrintJobBlocker(newJob, PrinterWindow.PauseComputerPrintTime,
                                              PrinterWindow.PausePrintLimit));
     }
     foreach (var oldData in BlockedUsers) {
         if ((oldData.MachineName == newJob.MachineName) && (oldData.UserName == newJob.User))
             return oldData.PagesAllocated;
     }
     return -1;
 }