简体   繁体   English

WCF服务中异步调用事件

[英]call event asynchronously in wcf service

I am implementing a third party service to get some feeds. 我正在实施第三方服务以获取一些提要。 sample code below. 下面的示例代码。 when I call the GetLiveFeed function the response is returned through an event HandleEvent. 当我调用GetLiveFeed函数时,响应是通过事件HandleEvent返回的。

public class WebComponent
{
    public string livefeed = string.Empty;

    public static string GetSerivceRequest()
    {
        WebComponent obj = new WebComponent();
        obj.GetResult();

        return obj.livefeed;
    }

    public void GetResult()
    {
        Service abc = new Service();
        abc.GetLiveFeed();
    }

    public void HandleEvent(Event eventObj)
    {
        livefeed = "Value from third party service";
    }

}

I want to wait in the static function Getservice until the event is raised and value is assigned in the livefeed variable. 我想在静态函数Getservice中等待,直到引发事件并在livefeed变量中分配了值。 But as of now I am only getting blank value. 但是截至目前,我只获得了空白的价值。 if I put thread.sleep than I get value which I don't want to use 如果我把thread.sleep比我得到我不想使用的价值

I was able to make the parent thread wait until the execution finishes in the child thread using AutoresetEvent functionality 我能够使用AutoresetEvent功能使父线程等到子线程中的执行完成

Tutorial 讲解

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM