我尝试使用 C# 中的 Windows 运行时从桌面应用获取我的 GPS 位置.
I trying to get my GPS position from a Desktop app, using Windows Runtime, in C#.
我按照 这个方法 进行设置使用 Visual Studio 和 此代码示例 创建以下内容作为 C# 控制台应用程序的简单代码:
I followed this how-to to set up Visual Studio and this code sample to create the following trivial code as a C# console app :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime;
using System.Windows;
using Windows;
using Windows.Devices.Geolocation;
using Windows.Foundation;
using Windows.Foundation.Collections;
namespace GeoLocCS
{
public sealed partial class Program
{
static void Main(string[] args)
{
Test test = new Test();
Console.Read();
}
}
public class Test
{
private Geolocator geolocator;
public Test()
{
Console.WriteLine("test");
geolocator = new Geolocator();
this.getPos();
}
async void getPos()
{
Geoposition pos = await geolocator.GetGeopositionAsync();
Console.WriteLine(pos.Coordinate.Latitude.ToString());
}
}
}
尝试编译时出现错误:
Error 1 'await' requires that the type 'Windows.Foundation.IAsyncOperation<Windows.Devices.Geolocation.Geoposition>' have a suitable GetAwaiter method. Are you missing a using directive for 'System'?
我尝试引用每个可以引用的 DLL,例如System.runtime"、System.Runtime.WindowsRuntime"、Windows.Foundation"...
I tried to reference every DLL that I could, like "System.runtime", "System.Runtime.WindowsRuntime", "Windows.Foundation"...
我错过了什么?
谢谢你的回答,
谢尔盖
我终于找到了我的问题:
I finally figured out my problem :
我手动引用了以下两个 DLL:
I manually referenced the two following DLLs :
C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5FacadesSystem.Runtime.dll
C:WindowsMicrosoft.NETFramework64v4.0.30319System.Runtime.WindowsRuntime.dll
这篇关于C#“等待"从桌面应用程序使用 WinRT 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!