【发布时间】:2014-02-11 19:04:26
【问题描述】:
我正在尝试查看Windows Phone Live tutorial,但在尝试实现代码示例时遇到了困难,因为它似乎缺少信息。
using System;
using System.Windows;
using System.Collections.Generic;
using Microsoft.Phone.Controls;
using Microsoft.Live;
using Microsoft.Live.Controls;
namespace WindowsPhoneCodeSample
{
public partial class MainPage : PhoneApplicationPage
{
private LiveConnectClient client;
public MainPage()
{
InitializeComponent();
}
private async void btnSignin_SessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
{
if (e.Status == LiveConnectSessionStatus.Connected)
{
client = new LiveConnectClient(e.Session);
LiveOperationResult operationResult = await client.GetAsync("me");
try
{
dynamic meResult = operationResult.Result;
if (meResult.first_name != null &&
meResult.last_name != null)
{
infoTextBlock.Text = "Hello " +
meResult.first_name + " " +
meResult.last_name + "!";
}
else
{
infoTextBlock.Text = "Hello, signed-in user!";
}
}
catch (LiveConnectException exception)
{
this.infoTextBlock.Text = "Error calling API: " +
exception.Message;
}
}
else
{
infoTextBlock.Text = "Not signed in.";
}
}
}
}
我明白了
Error 2 The name 'await' does not exist in the current context
Error 3 One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll?
我是否遗漏了一些参考资料或其他什么?
编辑
本教程似乎做得不好或非常过时。我制作了一个 windows phone 8 应用程序,但由于“await”t 关键字,它仍然无法构建。
The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.
client.GetAsync is also a void method. So not sure how it returns something as well.
【问题讨论】:
-
await 和 async 是 .NET 4.5 的特性。 Windows Phone 7 是否使用 .NET 4.5?
-
@MailmanOdd: nuget.org/packages/microsoft.bcl.async
-
嗯,我想本教程会说我需要一个 3rd 方包。
-
您使用的是哪个版本的 Visual Studio?
-
@chobo2:它不是第 3 方——它来自微软。我仍然很惊讶它没有提到它。顺便说一句,您是在为 Windows Phone 7.5 开发吗?
标签: c# windows-phone-7 async-await live