如何将方法转换为异步

时间:2019-09-24 15:38:55

标签: c#

我有这段代码,我如何将其转换为异步,我尝试用readtoend更改readtoendasync,但是......

public HttpWebResponse smethod_1(ref HttpWebRequest httpWebRequest_0)
{
     HttpWebResponse httpWebResponse;
     try
     {
         httpWebRequest_0.Method = "GET";
         httpWebResponse = (HttpWebResponse)httpWebRequest_0.GetResponse();
     }
     catch (Exception ex)
     {
         ProjectData.SetProjectError(ex);
         httpWebResponse = (HttpWebResponse)null;
         ProjectData.ClearProjectError();
     }
     return httpWebResponse;
}
public string method_0(ref HttpWebRequest httpWebRequest0)
{
    return new StreamReader(this.smethod_1(ref httpWebRequest0).GetResponseStream(), Encoding.UTF8, true).ReadToEnd();
}
public string Smethod0(ref HttpWebRequest httpWebRequest0)
{
    return new StreamReader(this.smethod_1(ref httpWebRequest0).GetResponseStream(), Encoding.UTF8, true).ReadToEnd();
}

我也尝试过

await httpWebRequest0_1.GetResponseAsync();

但是它返回我错误

0 个答案:

没有答案