开发者

Duplex services / Singleton class with background thread

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.

The class Scenariocomponent is a singleton (following).

    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.
        }
开发者_StackOverflow社区
        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);
        }
    }

Initially I was using MSMQ to update the UI as it worked sufficiently however this is no longer acceptable due to client restrictions.

My Service is as follows:

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

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.

Thank you!


Instead of using WinForms, you could use WPF and binding, which would handle the updating for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜