如何激活在C#中的任务吗? [英] How to activate task in c#?

查看:118
本文介绍了如何激活在C#中的任务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我'试图消耗在Windows 8一个WCF:
我的code消耗由WCF服务生成的方法:

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

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

}

任务citiesResponse的状态为WaitingForACtivati​​on的结果=还没有已计算

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

推荐答案

你没有添加异步并等待得到的结果类型,而不是任务类型??

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

应该是这样的:

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

而在方法,你应该添加异步

And in the method you should add async

这篇关于如何激活在C#中的任务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆