title: Prevent duplicate objects being added to List<object> while retaining the ability to have two object of the same name?
body: <p>I have attempted this over and over, but I'm now just going in circles.</p>
  
  <p>I have a set of mostly unique job files stored externally, from these files I'm collection information and storing it in my program via a List.</p>
  
  <p>On occasion, I have two job files named the same (this unfortunately cant be avoided) but containing different data (the most unique of which is a DateTime string).</p>
  
  <p>My program works by polling 3 locations for these files (all locations are mirrored so the same data is present in each), collecting the information then outputting the info to a ListView window dependent on current status of each job file.</p>
  
  <p>The issue I'm having is preventing duplicate entries being added to my List resulting in 69 objects in the list for only 23 jobs files.</p>
  
  <p>To avoid having duplicates output in the listview, I attempted to use a dictionary to store known keys based on the job file name, however this falls over when reaching the second file that is named the same as an existing entry. Resulting in me only seeing 21 jobs in a list that should contain 23 (I also get an exception thrown). I got around this by appending something to the end of the second entry, but this isn't ideal, and was found to cause other complications later on.</p>
  
  <p>Any ideas?</p>
  
  <p>Here's what I have so far.</p>
  
  <pre><code>public List&lt;object&gt; PendingJobsArray = new List&lt;object&gt;();
  public List&lt;object&gt; ActiveJobsArray = new List&lt;object&gt;();
  public List&lt;object&gt; CompletedJobsArray = new List&lt;object&gt;();
  
  public JobObject PendingJobs = new JobObject();
  public JobObject ActiveJobs = new JobObject();
  public JobObject CompletedJobs = new JobObject();
  
      private void updatePending(int index, XmlParser xmlParser)
      {
          if (Program.PendingJobsArray.Count == 0)
          {
              Program.KnownPendingJobs.Add(xmlParser.getElementAttrValue(index, "Name"), xmlParser.getElementAttrValue(index, "DateTime"));
              JobObject PendingJobs = new JobObject();
              PendingJobs.jobObjectName = xmlParser.getElementAttrValue(index, "Name");
              PendingJobs.jobObjectState = xmlParser.getElementAttrValue(index, "State");
              PendingJobs.jobObjectDiscName = xmlParser.getElementAttrValue(index, "DiscName");
              PendingJobs.jobObjectPercentComplete = Convert.ToInt32(xmlParser.getElementAttrValue(index, "TotalPercentComplete"));
              PendingJobs.jobObjectDateTime = xmlParser.getElementAttrValue(index, "DateTime");
              PendingJobs.jobObjectRequested = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Requested"));
              PendingJobs.jobObjectCompleted = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Completed"));
              PendingJobs.jobObjectFailed = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Failed"));
              PendingJobs.jobObjectPriority = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Priority"));
              // PendingJobs.jobObjectServer = xmlParser.getElementAttrValue("Server");
              // PendingJobs.jobObjectOperation = xmlParser.getElementAttrValue("Operation");
              Program.PendingJobsArray.Add(PendingJobs);
          }
          else if (Program.KnownPendingJobs.ContainsKey(xmlParser.getElementAttrValue(index, "Name")))
          {
              for (int i = 0; i &lt; Program.PendingJobsArray.Count; ++i)
              {
                  if (xmlParser.getElementAttrValue(index, "State") == "Write")
                  {
                      Program.PendingJobsArray.RemoveAt(index);
                  }
                  else
                  {
                      PendingJobs.jobObjectName = xmlParser.getElementAttrValue(index, "Name");
                      PendingJobs.jobObjectState = xmlParser.getElementAttrValue(index, "State");
                      PendingJobs.jobObjectDiscName = xmlParser.getElementAttrValue(index, "DiscName");
                      PendingJobs.jobObjectPercentComplete = Convert.ToInt32(xmlParser.getElementAttrValue(index, "TotalPercentComplete"));
                      PendingJobs.jobObjectDateTime = xmlParser.getElementAttrValue(index, "DateTime");
                      PendingJobs.jobObjectRequested = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Requested"));
                      PendingJobs.jobObjectCompleted = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Completed"));
                      PendingJobs.jobObjectFailed = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Failed"));
                      PendingJobs.jobObjectPriority = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Priority"));
                      Program.PendingJobsArray[index] = PendingJobs;
                  }
              }
          }
          else if (Program.KnownPendingJobs.ContainsKey(xmlParser.getElementAttrValue(index, "Name")))
          }
          else
          {
              Program.KnownPendingJobs.Add(xmlParser.getElementAttrValue(index, "Name"), xmlParser.getElementAttrValue(index, "DateTime"));
              JobObject PendingJobs = new JobObject();
              PendingJobs.jobObjectName = xmlParser.getElementAttrValue(index, "Name");
              PendingJobs.jobObjectState = xmlParser.getElementAttrValue(index, "State");
              PendingJobs.jobObjectDiscName = xmlParser.getElementAttrValue(index, "DiscName");
              PendingJobs.jobObjectPercentComplete = Convert.ToInt32(xmlParser.getElementAttrValue(index, "TotalPercentComplete"));
              PendingJobs.jobObjectDateTime = xmlParser.getElementAttrValue(index, "DateTime");
              PendingJobs.jobObjectRequested = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Requested"));
              PendingJobs.jobObjectCompleted = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Completed"));
              PendingJobs.jobObjectFailed = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Failed"));
              PendingJobs.jobObjectQuantity = xmlParser.getElementAttrValue(index, "Quantity");
              PendingJobs.jobObjectPriority = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Priority"));
              //PendingJobs.jobObjectServer = xmlParser.getElementAttrValue("Server");
              //PendingJobs.jobObjectOperation = xmlParser.getElementAttrValue("Operation");
              Program.PendingJobsArray.Add(PendingJobs);
          }
      }
  </code></pre>
  
  <p><strong>Updated</strong> code based on comments below,</p>
  
  <pre><code>    using System;
      using System.Collections.Generic;
      using System.Collections.Specialized;
      using System.Collections;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using System.Threading;
      using System.Windows.Forms;
  
      namespace SOERequestProgress
      {
          class XmlSplitter
          {
              // Declarations
              private static string[] COMPLETED_STATES = new string[2]
          {
            "ERROR",
            "COMPLETE"
          };
  
              private static string[] PENDING_STATES = new string[1]
          {
            "PENDING"
          };
  
              private static string[] ACTIVE_STATES = new string[1]
          {
            "PAUSED"
          };
  
              private const string STATE_ERROR = "ERROR";
              private const string STATE_COMPLETE = "COMPLETE";
              private const string STATE_PENDING = "PENDING";
              private const string STATE_ACTIVE = "PAUSED";
  
              public static JobObject PendingJobs = new JobObject();
              public static JobObject CompletedJobs = new JobObject();
              public static JobObject ActiveJobs = new JobObject();
  
              //public static JobObject x;
  
              public static int intI = 0;
  
              // Add additional info from parsed XML (Currently only "Name" and "State" are collected.
              public static void splitXml(string JobList, out List&lt;JobObject&gt; Active, out List&lt;JobObject&gt; Completed, out List&lt;JobObject&gt; Pending)
              {
                  bool flag = false;
                  int num1 = 0;
                  string text = "";
                  string xmlString = "";
                  while (!flag)
                  {
                      if (num1 &lt; 3)
                      {
                          try
                          {
                              xmlString = JobList;
                              flag = true;
                          }
                          catch (Exception ex)
                          {
                              ++num1;
                              text = text + "Try (" + num1.ToString() + ") " + ex.Message + "\n";
                              Thread.Sleep(1000);
                          }
                      }
                      else
                          break;
                  }
                  if (!flag)
                  {
                      int num2 = (int)MessageBox.Show(text, "Job list error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                  }
                  else
                  {
                      XmlParser xmlParser = new XmlParser();
                      if (!xmlParser.setXmlString(xmlString))
                      {
                          int num3 = (int)MessageBox.Show("Error parsing job list server response.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                          flag = false;
                      }
                      else
                      {
                          int num3 = xmlParser.setElementName("Job");
                          for (int index = 0; index &lt; num3; ++index)
                          {
                              string elementAttrValue1 = xmlParser.getElementAttrValue(index, "Name");
                              string elementAttrValue2 = xmlParser.getElementAttrValue(index, "State");
                              if (isState(elementAttrValue2, PENDING_STATES))
                              {
                                  updatePending(index, xmlParser);
                              }
                              else if (isState(elementAttrValue2, COMPLETED_STATES))
                              {
                                  updateCompleted(index, xmlParser);
                              }
                              else //if (isState(elementAttrValue2, ACTIVE_STATES))
                              {
                                  updateActive(index, xmlParser);
                              }
                          }
                      }
                  }
                  Active = Program.ActiveJobsArray;
                  Completed = Program.CompletedJobsArray;
                  Pending = Program.PendingJobsArray;
              }
  
              private static void updatePending(int index, XmlParser xmlParser)
              {
                  var jobName = xmlParser.getElementAttrValue(index, "Name");
                  var pendingJob = Program.PendingJobsArray.Find(x =&gt; x.jobObjectName == jobName);
  
                  if (pendingJob == null)
                  {
                      JobObject newPendingJob = CreateJob("Pending", index, xmlParser);
                      Program.PendingJobsArray.Add(newPendingJob);
                  }
              }
  
              private static void updateCompleted(int index, XmlParser xmlParser)
              {
                  var jobName = xmlParser.getElementAttrValue(index, "Name");
                  var CompletedJob = Program.CompletedJobsArray.Find(x =&gt; x.jobObjectName == jobName);
  
                  if (CompletedJob == null)
                  {
                      JobObject newCompletedJob = CreateJob("Completed", index, xmlParser);
                      Program.CompletedJobsArray.Add(newCompletedJob);
                  }
              }
  
              private static void updateActive(int index, XmlParser xmlParser)
              {
                  var jobName = xmlParser.getElementAttrValue(index, "Name");
                  var activeJob = Program.ActiveJobsArray.Find(x =&gt; x.jobObjectName == jobName);
  
                  if (activeJob == null)
                  {
                      JobObject newActiveJob = CreateJob("Active", index, xmlParser);
                      Program.ActiveJobsArray.Add(newActiveJob);
                  }
              }
  
              private static JobObject CreateJob(string jobType, int index, XmlParser xmlParser)
              {
                  if (jobType == "Pending")
                  {
                      JobObject x = new JobObject();
                      x.jobObjectName = xmlParser.getElementAttrValue(index, "Name");
                      x.jobObjectState = xmlParser.getElementAttrValue(index, "State");
                      x.jobObjectDiscName = xmlParser.getElementAttrValue(index, "DiscName");
                      x.jobObjectPercentComplete = Convert.ToInt32(xmlParser.getElementAttrValue(index, "TotalPercentComplete"));
                      x.jobObjectDateTime = xmlParser.getElementAttrValue(index, "DateTime");
                      x.jobObjectRequested = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Requested"));
                      x.jobObjectCompleted = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Completed"));
                      x.jobObjectFailed = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Failed"));
                      x.jobObjectQuantity = xmlParser.getElementAttrValue(index, "Quantity");
                      x.jobObjectPriority = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Priority"));
                      //x.jobObjectServer = xmlParser.getElementAttrValue("Server");
                      //x.jobObjectOperation = xmlParser.getElementAttrValue("Operation");
                      return x;
                  }
                  if (jobType == "Completed")
                  {
                      JobObject x = new JobObject();
                      x.jobObjectName = xmlParser.getElementAttrValue(index, "Name");
                      x.jobObjectState = xmlParser.getElementAttrValue(index, "State");
                      x.jobObjectDiscName = xmlParser.getElementAttrValue(index, "DiscName");
                      x.jobObjectPercentComplete = Convert.ToInt32(xmlParser.getElementAttrValue(index, "TotalPercentComplete"));
                      x.jobObjectDateTime = xmlParser.getElementAttrValue(index, "DateTime");
                      x.jobObjectRequested = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Requested"));
                      x.jobObjectCompleted = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Completed"));
                      x.jobObjectFailed = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Failed"));
                      //x.jobObjectServer = xmlParser.getElementAttrValue("Server");
                      //x.jobObjectOperation = xmlParser.getElementAttrValue("Operation");
                      return x;
                  }
  
                  if (jobType == "Active")
                  {
                      JobObject x = new JobObject();
                      x.jobObjectName = xmlParser.getElementAttrValue(index, "Name");
                      x.jobObjectState = xmlParser.getElementAttrValue(index, "State");
                      x.jobObjectDiscName = xmlParser.getElementAttrValue(index, "DiscName");
                      x.jobObjectPercentComplete = Convert.ToInt32(xmlParser.getElementAttrValue(index, "TotalPercentComplete"));
                      x.jobObjectDateTime = xmlParser.getElementAttrValue(index, "DateTime");
                      x.jobObjectRequested = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Requested"));
                      x.jobObjectCompleted = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Completed"));
                      x.jobObjectFailed = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Failed"));
                      x.jobObjectPriority = Convert.ToInt32(xmlParser.getElementAttrValue(index, "Priority"));
                      //x.jobObjectServer = xmlParser.getElementAttrValue("Server");
                      //x.jobObjectOperation = xmlParser.getElementAttrValue("Operation");
                      return x;
                  }
                  return null;
              }
  
              private static bool isState(string jobState, string[] knownStates)
              {
                  bool flag = false;
                  for (int index = 0; index &lt; knownStates.Length; ++index)
                  {
                      if (jobState.ToUpper().Equals(knownStates[index]))
                      {
                          flag = true;
                          //break;
                      }
                  }
                  return flag;
              }
          }
      }
  </code></pre>
  
  <p>This new code doesn't appear to be correct and I cant see where its failing, but its filling my CompletedJobArray with over 200 entries in a matter of seconds.</p>
  
  <p>My ListView is only showing 1 entry (its filtered for unique jobs) and on checking the contents of the Array, its adding the same jobObject for all 200+ entries.</p>
  
  <p>Can anyone spot the flaw in this code?  </p>
  
  <p><strong>Update 2:</strong> IEqualityComparer implemented, further errors encountered.</p>
  
  <p>The below code are the implementation of Equals and GetHashCode. </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace SOERequestProgress
  {
      class JobComparer : IEqualityComparer&lt;JobObject&gt;
      {
          public JobComparer(Func&lt;JobObject, object&gt; keySelector)
          {
              KeySelector = keySelector;
          }
  
          public bool Equals(JobObject x, JobObject y)
          {
              return KeySelector(x).Equals(KeySelector(y));
                  //x.jobObjectName == y.jobObjectName &amp;&amp;
                  //x.jobObjectDateTime == y.jobObjectDateTime;
          }
  
          public int GetHashCode(JobObject job)
          {
               return KeySelector(job).GetHashCode();
          }
      }
  }
  </code></pre>
  
  <p>This implementation throws the errors below,</p>
  
  <pre><code>Error   1   'SOERequestProgress.JobObject' does not implement interface member 'System.Collections.Generic.IEqualityComparer&lt;SOERequestProgress.JobComparer&gt;.GetHashCode(SOERequestProgress.JobComparer)'   C:\Users\youngs\Documents\Visual Studio 2012\Projects\SOERequestProgress\SOERequestProgress\SOERequestProgress\JobObject.cs 9   11  SOERequestProgress
  
  Error   2   'SOERequestProgress.JobObject' does not implement interface member 'System.Collections.Generic.IEqualityComparer&lt;SOERequestProgress.JobComparer&gt;.Equals(SOERequestProgress.JobComparer, SOERequestProgress.JobComparer)'    C:\Users\youngs\Documents\Visual Studio 2012\Projects\SOERequestProgress\SOERequestProgress\SOERequestProgress\JobObject.cs 9   11  SOERequestProgress
  </code></pre>
  
  <p><strong>Update 3:</strong> Ok I'm nearly about to admit defeat, as I don't seem to be able to get my head round how the IEqualityComparer works... and I'm back to banging me head on the keyboard >.&lt;</p>
  
  <p>The code below now gets 72 jobs in the CompletedJobsArray, which equates to 24 jobs duplicated 3 times!!!</p>
  
  <pre><code>private static void updateCompleted(int index, XmlParser xmlParser)
          {
              var jobName = xmlParser.getElementAttrValue(index, "Name");
              var jobDate = xmlParser.getElementAttrValue(index, "DateTime");
              // Commented line below has same affect as uncommented line, except it always returns true....
              //var CompletedJobs = Program.CompletedJobsArray.Distinct(new JobComparer(x =&gt; new { x.jobObjectName, x.jobObjectDateTime }));
              var CompletedJobs = Program.CompletedJobsArray.Find(x=&gt;x.Equals(jobDate));
  
              if (CompletedJobs == null)
              {
                  JobObject newCompletedJob = CreateJob("Completed", index, xmlParser);
                  Program.CompletedJobsArray.Add(newCompletedJob);
              }
              else
              {
                  // Code below causes issues with IEnumerable
                  //UpdateJob("Completed", index, CompletedJobs, xmlParser);
              }
          }
  </code></pre>
  
  <p>I have 24 jobs, but when the poll of the 3 locations for these job files happens, I only need the 24 unique jobs added to the array.... What am I doing wrong?</p>
  
  <p><strong>Update 4</strong> Duplication still occurs... but not in the List...</p>
  
  <p>Ok, so a little further on, and I am finding that my List conatins the correct number of jobs, with no duplication occuring.</p>
  
  <p>However, when a new job enters the List, output from the program (in the UI) gets duplicated for some jobs but not all.</p>
  
  <p>I cant seem to pin down a reason for this, as I've tried to keep things as simple as possible, and am using one list (which is confirmed as working as intended) and am generating my output to a listview from there.</p>
  
  <p>Heres offending section of code,</p>
  
  <pre><code>private void SortViews()
  {
      var Jobs = Program.JobsArray;
      Program.JobsArray.Sort((a, b) =&gt; String.Compare(a.jobObjectDateTime, b.jobObjectDateTime));
      if (Jobs.Count &gt;= 0)
      {
          foreach (JobObject Job in Jobs.Where(x =&gt; PENDING_STATES.Contains(x.jobObjectState)))
          {
              if (Job.inPendingView &amp;&amp; Job.inPendingView)
              {
                  Job.inCompletedView = false;
                  CompletedJobsView.Items.Remove(PendingJobsView.FindItemWithText(Job.jobObjectName));
                  Job.inActiveView = false;
                  ActiveJobsView.Items.Remove(ActiveJobsView.FindItemWithText(Job.jobObjectName));
                  ListViewItem item = PendingJobsView.FindItemWithText(Job.jobObjectDateTime);
                  item.SubItems[0].Text = Job.jobObjectName;
                  item.SubItems[1].Text = Convert.ToString(Job.jobObjectPriority);
                  item.SubItems[2].Text = Job.jobObjectDiscName;
                  item.SubItems[3].Text = Convert.ToString(Job.jobObjectRequested);
                  item.SubItems[4].Text = Job.jobObjectDateTime;
              }
              else
              {
                  string[] brr = new string[6];
                  ListViewItem item;
                  brr[0] = Job.jobObjectName;
                  brr[1] = Convert.ToString(Job.jobObjectPriority);
                  brr[2] = Job.jobObjectDiscName;
                  brr[3] = Convert.ToString(Job.jobObjectRequested);
                  brr[4] = Job.jobObjectDateTime;
                  item = new ListViewItem(brr);
                  item.ForeColor = Color.Blue;
                  PendingJobsView.Items.Add(item);
                  Job.inPendingView = true;
                  Job.inActiveView = false;
                  Job.inCompletedView = false;
                  Job.isActive = false;
                  Job.isCompleted = false;
                  Job.isPending = true;
              }
          }
  
          foreach (JobObject Job in Jobs.Where(x =&gt; ACTIVE_STATES.Contains(x.jobObjectState)))
          {
              if (Job.isActive &amp;&amp; Job.inActiveView)
              {
                  Job.inPendingView = false;
                  PendingJobsView.Items.Remove(PendingJobsView.FindItemWithText(Job.jobObjectName));
                  Job.inCompletedView = false;
                  CompletedJobsView.Items.Remove(CompletedJobsView.FindItemWithText(Job.jobObjectDateTime));
                  //ActiveJobsView.Refresh();
                  ListViewItem item = ActiveJobsView.FindItemWithText(Job.jobObjectName);
                  item.SubItems[0].Text = Job.jobObjectName;
                  item.SubItems[1].Text = Convert.ToString(Job.jobObjectPriority);
                  item.SubItems[2].Text = Job.jobObjectDiscName;
                  item.SubItems[3].Text = Convert.ToString(Job.jobObjectCompleted) + " of " + Convert.ToString(Job.jobObjectRequested);
                  item.SubItems[4].Text = Convert.ToString(Job.jobObjectFailed);
                  item.SubItems[5].Text = Convert.ToString(Job.percentComplete) + "%";
                  item.SubItems[6].Text = Convert.ToString(Job.jobObjectState);
              }
              else
              {
                  Job.isActive = true;
                  string[] crr = new string[7];
                  ListViewItem item;
                  crr[0] = Job.jobObjectName;
                  crr[1] = Convert.ToString(Job.jobObjectPriority); 
                  crr[2] = Job.jobObjectDiscName;
                  crr[3] = Convert.ToString(Job.jobObjectCompleted) + " of " + Convert.ToString(Job.jobObjectRequested);
                  crr[4] = Convert.ToString(Job.jobObjectFailed);
                  crr[5] = Convert.ToString(Job.percentComplete) + "%";
                  crr[6] = Convert.ToString(Job.jobObjectState);
                  item = new ListViewItem(crr);
                  item.ForeColor = Color.DarkOrange;
                  ActiveJobsView.Items.Add(item);
                  Job.inActiveView = true;
                  Job.inPendingView = false;
                  Job.inCompletedView = false;
                  Job.isActive = true;
                  Job.isCompleted = false;
                  Job.isPending = false;
              }
          }
  
          foreach (JobObject Job in Jobs.Where(x =&gt; COMPLETED_STATES.Contains(x.jobObjectState)))
          {
              if (Job.isCompleted &amp;&amp; Job.inCompletedView)
              {
                  Job.inPendingView = false;
                  PendingJobsView.Items.Remove(PendingJobsView.FindItemWithText(Job.jobObjectName));
                  Job.inActiveView = false;
                  ActiveJobsView.Items.Remove(ActiveJobsView.FindItemWithText(Job.jobObjectName));
                  //CompletedJobsView.Refresh();
                  ListViewItem item = CompletedJobsView.FindItemWithText(Job.jobObjectName);
                  item.SubItems[0].Text = Job.jobObjectName;
                  item.SubItems[1].Text = Job.jobObjectDiscName;
                  item.SubItems[2].Text = Convert.ToString(Job.jobObjectCompleted) + " of " + Convert.ToString(Job.jobObjectRequested);
                  item.SubItems[3].Text = Convert.ToString(Job.jobObjectFailed);
                  item.SubItems[4].Text = Convert.ToString(Job.jobObjectState);
                  item.SubItems[5].Text = Job.jobObjectDateTime;
              }
              else
              {
                  string[] arr = new string[6];
                  ListViewItem item;
                  arr[0] = Job.jobObjectName;
                  arr[1] = Job.jobObjectDiscName;
                  arr[2] = Convert.ToString(Job.jobObjectCompleted) + " of " + Convert.ToString(Job.jobObjectRequested);
                  arr[3] = Convert.ToString(Job.jobObjectFailed);
                  arr[4] = Convert.ToString(Job.jobObjectState);
                  arr[5] = Job.jobObjectDateTime;
                  item = new ListViewItem(arr);
                  if (Job.jobObjectState == "ERROR")
                  {
                      item.ForeColor = Color.Firebrick;
                  }
                  if (Job.jobObjectState == "COMPLETE")
                  {
                      item.ForeColor = Color.Green;
                  }
                  CompletedJobsView.Items.Add(item);
                  Job.inCompletedView = true;
                  Job.inPendingView = false;
                  Job.inActiveView = false;
                  Job.isCompleted = true;
                  Job.isActive = false;
                  Job.isPending = false;
              }
          }   
      }
  }
  </code></pre>
  
  <p>Any ideas whats causing this behavior?</p>
  
  <p>Thanks again :)</p>