我正在使用用户名和密码调用此静态登录方法。我希望它等到下载字符串异步完成后再返回。对于我这该死的生活,我不能让它等待。
我试过老派
while(wc.IsBusy){} //Which froze
还尝试了各种甚至没有编译的异步废话
public static dbObj Login(String username, String password)
{
dbObj ret = new dbObj();
String rawWebReturn = "";
ret.propBag.Add(_BAGTYPE,returnTypes.Login.ToString());
DateTime date = DateTime.Now;
WebClient wc = new WebClient();
wc.DownloadStringAsync(new Uri(baseLoginURI + "uname=" + username + "&pword=" + password + "&date=" + date.ToString()));
wc.DownloadStringCompleted += (s,e) => {
if(e.Error!=null)
rawWebReturn = e.Error.Message;
else
rawWebReturn = e.Result;
};
return parseWebReturn(rawWebReturn,ret);
}