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变化或已完成,但我不确定如何做到这一点。任何反馈将不胜感激。
谢谢!
我同意WPF将是一个很好的选择,但不幸的是,客户端仅限于我们提到的技术。 – Elixir 2010-11-05 09:12:21