怎样才能回到“空虚”;种类

本文关键字:空虚 种类 | 更新日期: 2023-09-27 18:02:06

我在windows phone 8.1上使用

try
{
    var Url = "https://...../oauth/authorize?client_id=" + Uri.EscapeDataString("4a3e...") + "&response_type=code&redirect_uri=" + Uri.EscapeDataString("http://localhost:8888/callback") + "&show_dialog=true";
    var StartUri = new Uri(Url);
    var EndUri = new Uri("http://localhost:8888/callback");
    WebAuthenticationBroker.AuthenticateAndContinue(StartUri, EndUri,null, WebAuthenticationOptions.None);
}
catch (Exception Error)
{
    //
    // Bad Parameter, SSL/TLS Errors and Network Unavailable errors are to be handled here.
    //
    var dialog = new MessageDialog(Error.Message);
    await dialog.ShowAsync();
}

因为WebAuthenticationBroker.AuthenticateAndContinuevoid类我不能把var t=WebAuthenticationBroker.AuthenticateAndContinue放在

我只想返回下面的代码

public async void ContinueWebAuthentication(WebAuthenticationBrokerContinuationEventArgs args)
{
    WebAuthenticationResult result = args.WebAuthenticationResult;
    if (result.ResponseStatus == WebAuthenticationStatus.Success)
    {
        //OutputToken(result.ResponseData.ToString());
        await GetUserNameAsync(result.ResponseData.ToString());
    }
    else if (result.ResponseStatus == WebAuthenticationStatus.ErrorHttp)
    {
        throw new Exception("HTTP Error returned by AuthenticateAsync() : " + result.ResponseErrorDetail.ToString());
    }
    else
    {
        throw new Exception("Error returned by AuthenticateAsync() : " + result.ResponseErrorDetail.ToString());
    }
}

怎样才能回到“空虚”;种类

void不是一个"类型",它只是意味着该方法没有返回值。不需要return语句

由于在异步方法中返回void不是好的做法:

https://msdn.microsoft.com/en-us/magazine/jj991977.aspx

Async void方法有不同的错误处理语义。当从异步任务或异步任务方法抛出异常时,将捕获该异常并将其放置在Task对象上。对于async void方法,没有Task对象,因此从async void方法抛出的任何异常将直接在async void方法启动时处于活动状态的SynchronizationContext上引发

你应该把void替换成Task

public async Task ContinueWebAuthentication(