title: Duplex services / Singleton class with background thread
body: <p>I'm wondering if anyone can help me. I have a wcf service running over TCP which will make use of a duplex service. currently this service calls a business object which in turn does some processing. While this processing is happening on a background thread I wish the UI to be updated at certain points. I've attached my code below. TestStatus should be broken up into six parts and the service should update the windows forms UI each time this changes.</p>
  
  <p>The class Scenariocomponent is a singleton (following).</p>
  
  <pre><code>    public void BeginProcessingPendingTestCases()
      {
          ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessPendingTestCases));
      }
      public void BeginProcessingPendingTestCases()
      {
          ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessPendingTestCases));
      }
  
      private void ProcessPendingTestCases(object state)
      {
          while (this.IsProcessingScenarios)
          {
              ProcessNextPendingTestCase();
          }
      }
  
      private void ProcessNextPendingTestCase()
      {
          while (this.ServiceStatus == Components.ServiceStatus.Paused)
          {
              //Wait.
          }
  
          var testOperation = this.PendingTestCases.Dequeue();
  
          if (testOperation.OperationStatus == TestStatus.Pending)
          {
              throw new NotImplementedException(); //TODO : Handle test.
  
              if (testOperation.OperationStatus != TestStatus.Failed)
              {
                  testOperation.OperationStatus = TestStatus.Processed;
              }
  
              this.CompletedTestCases.Enqueue(testOperation);
          }
      }
  </code></pre>
  
  <p>Initially I was using MSMQ to update the UI as it worked sufficiently however this is no longer acceptable due to client restrictions.</p>
  
  <p>My Service is as follows:</p>
  
  <pre><code>public class TestHarnessService : ITestHarnessService
  {
      public bool Ping()
      {
          return true;
      }
  
      public bool IsProcessingScenarios()
      {
          return ScenarioComponent.Instance.IsProcessingScenarios;
      }
  
      public void BeginProcessingScenarios(string xmlDocument, Uri webServiceUri)
      {
          var doc = new XmlDocument();
          doc.LoadXml(xmlDocument);
  
          var scenarios = ScenarioComponent.Deserialize(doc);
          ScenarioComponent.Instance.EnqueueScenarioCollection(scenarios, webServiceUri);
          ScenarioComponent.Instance.BeginProcessingPendingTestCases();
      }
  
      public void ValidateScenarioDocument(string xmlDocument)
      {
          var doc = new XmlDocument();
          doc.LoadXml(xmlDocument);
  
          ScenarioComponent.ValidateScenarioSchema(doc);
      }
  
      ITestOperationCallBack Callback
      {
          get
          {
              return OperationContext.Current.GetCallbackChannel&lt;ITestOperationCallBack&gt;();
          }
      }
  </code></pre>
  
  <p>Now I need the UI to update each time a testoperation changes or completes but I am unsure how to accomplish this. Any feedback would be greatly appreciated.</p>
  
  <p>Thank you!</p>