Office365 中的异步等待 API
async-await in Office365 API
我对 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()
Testikus tst = new Testikus();
Task tsk = new Task(tst.doLoadEvents);
tsk.Start();
tsk.Wait();
我对 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()
Testikus tst = new Testikus();
Task tsk = new Task(tst.doLoadEvents);
tsk.Start();
tsk.Wait();