2010-11-04 11 views
0

我想知道是否有人可以幫助我。我有一個通過TCP使用雙工服務的wcf服務。目前該服務調用一個業務對象,然後進行一些處理。雖然這個處理是在後臺線程上發生的,但我希望在某些時候更新UI。我在下面附上我的代碼。 TestStatus應該被分成六個部分,服務應該每次更改時更新Windows窗體UI。雙工服務/單線類與後臺線程

類ScenarioComponent是一個單例(以下)。

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); 
     } 
    } 

最初我使用MSMQ更新UI,因爲它的工作足夠,但由於客戶端的限制,這已不再可接受。

我的服務如下:

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<ITestOperationCallBack>(); 
     } 
    } 

現在我需要的UI每次更新testoperation變化或已完成,但我不確定如何做到這一點。任何反饋將不勝感激。

謝謝!

回答

0

而不是使用WinForms,您可以使用WPF和綁定,這將爲您處理更新。

+0

我同意WPF將是一個很好的選擇,但不幸的是,客戶端僅限於我們提到的技術。 – Elixir 2010-11-05 09:12:21