简体   繁体   中英

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.

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. 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

I was able to make the parent thread wait until the execution finishes in the child thread using AutoresetEvent functionality

Tutorial

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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