有没有办法可以将TaskHttpResponseMessage类型返回给HttpResponseMessage类型?下面是代码。
private HttpResponseMessage Process(string receiver,HttpRequestMessage request)
{
Reciever test = new Reciever();
Task<HttpResponseMessage> res= test.ReceiveAsync(receiver, request);
return res;
}
实际上我的 ReceiveAsync 方法属于异步类型,我不希望进程方法为异步类型
对此有什么想法吗?
谢谢!
答案 0 :(得分:-1)
我认为这可行:
编辑:不要这样做,因为它会死锁 - 谢谢@Servyprivate HttpResponseMessage Process(string receiver, HttpRequestMessage request)
{
return ProcessAsync(receiver, request).Result;
}
private async Task<HttpResponseMessage> ProcessAsync(string receiver, HttpRequestMessage request)
{
Reciever test = new Reciever();
var res = await test.ReceiveAsync(receiver, request);
return res;
}