C# Office365 API中的异步等待

C# Office365 API中的异步等待,c#,async-await,office365,C#,Async Await,Office365,我对C#比较陌生,因此我在理解office 365 API上下文中的异步等待逻辑时遇到了一些问题。当我使用简单的AcquireToken()过程时,我很容易获得令牌,但是当我使用异步方式时,我的程序范围就消失了,我真的不知道该怎么办 public class Testikus { private Uri serviceEndpointUri = new Uri("https://outlook.office365.com/api/v1.0/"); private string a

我对C#比较陌生,因此我在理解office 365 API上下文中的异步等待逻辑时遇到了一些问题。当我使用简单的AcquireToken()过程时,我很容易获得令牌,但是当我使用异步方式时,我的程序范围就消失了,我真的不知道该怎么办

public class Testikus
{
    private Uri serviceEndpointUri = new Uri("https://outlook.office365.com/api/v1.0/");
    private string athUrl = "https://outlook.office365.com/";
    private OfcIntCns cnsHlp = new OfcIntCns();

    public async Task doLoadEvents()
    {

        try
        {
            OutlookServicesClient client = new OutlookServicesClient(serviceEndpointUri, async () =>
            {

                AuthenticationContext ac = new AuthenticationContext(cnsHlp.Ath);
                ClientCredential cliCred = new ClientCredential("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy=");
                AuthenticationResult ar = await ac.AcquireTokenAsync(athUrl, cliCred); // From this point my scope is gone ....

                return ar.AccessToken;
            });
            var evt = await client.Me.Calendar.Events.ExecuteAsync(); 
            MessageBox.Show("I MADE IT HERE");

        }catch(Exception e){
            MessageBox.Show(e.Message);
        }

    }

确定错误不是调用Start()和Wait()


“我的作用域消失”是什么意思?AuthenticationResult ar=await ac.AcquireTokenAsync(athUrl,cliCred);已被访问,但它从未提供结果,我的程序将在其他地方继续。它甚至不会抛出异常。您如何调用
doLoadEvents
;tsts.doLoadEvents();您是否尝试在
return ar.AccessToken?从哪里调用此代码?您是否在
async
方法中?
        Testikus tst = new Testikus();
        Task tsk = new Task(tst.doLoadEvents);
        tsk.Start();
        tsk.Wait();