如何从异步任务返回和获取? [英] How to Return and Get from async Task?
问题描述
我正在尝试使用异步任务来发送电子邮件并返回状态代码但是需要帮助才能解决问题..
< span style ="font-size:medium">为了仅解决编译错误,请尝试以下操作:
&NBSP;&NBSP;
var r = SendMessage()。结果;
if(r == HttpStatusCode.OK)
{
。 。 。
但也要考虑下一个方法:
< span style ="margin:0px">
async void btnSendMessage_Clicked(object sender,System.EventArgs e)
{
&NBSP; &NBSP; var r = await SendMessage();
&NBSP; &NBSP; if(r == HttpStatusCode.OK)
&NBSP; &NBSP; {
&NBSP;&NBSP;
。 。 跨度> 跨度>
Hi,
I am trying to use async Task to send email and return the status code but straggling and need help please..
In order to solve the compilation error only, try this:
var r = SendMessage().Result;
if( r == HttpStatusCode.OK )
{ . . .
But consider the next approach too:
async void btnSendMessage_Clicked( object sender, System.EventArgs e)
{
var r = await SendMessage();
if( r == HttpStatusCode.OK )
{
. . .
这篇关于如何从异步任务返回和获取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!