How to activate task in c#?

匆匆过客 提交于 2019-12-12 06:35:45

问题


I'am trying to consume a wcf in windows 8: My code to consume the method generated by the WCF service:

public System.Threading.Tasks.Task<Maquette_MyAirport_Win8.FlightService.CitiesResponse> 
    GetAllCitiesAsync(Maquette_MyAirport_Win8.FlightService.BaseRequest request)
{
    return base.Channel.GetAllCitiesAsync(request);
}

is

public testproxy()
{
    _client = new FlightInfoServiceClient(Maquette_MyAirport_Win8.FlightService.FlightInfoServiceClient.EndpointConfiguration.wsHttpBindingConfiguration);
    BaseRequest req = new BaseRequest();
    System.Threading.Tasks.Task<Maquette_MyAirport_Win8.FlightService.CitiesResponse> CitiesResponse = _client.GetAllCitiesAsync( new BaseRequest());
    CitiesResponse.ContinueWith(task => citiesL = task.Result.Cities.FirstOrDefault(););

}

The status of the task citiesResponse is "WaitingForACtivation" and Result="Not yet Computed"

How can I Activate the task and how can i obtain the result??


回答1:


Don't you have to add async and await to get the result type instead of Task type??

It should be something like this:

var result = await _client.GetAllCitiesAsync( new BaseRequest());

And in the method you should add async



来源:https://stackoverflow.com/questions/12508643/how-to-activate-task-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!