应用程序不会崩溃,调试,但正常运行时 [英] App Doesn't Crash While Debugging, but Does When Running Normally
问题描述
系统信息
- 的Windows 10技术preVIEW(建设9926)
- 的Visual Studio 2013社区
,试图在调试:
- 的 [AT& T公司] 的的Lumia 635(用于手机的Windows 10技术preVIEW建立9941瓦特/青色的Lumia)
- 的 [AT& T公司] 的的Lumia 1520(Windows Phone的8.1的Lumia牛仔和PFD)
- 的 [锁定] 的BLU赢JR(的Windows Phone 8.1,具有PFD)
- 的 [威瑞森] 的的Lumia图标(Windows Phone的8.1的Lumia牛仔和PFD)
块引用>我试图让我的应用程序工作的定位服务。 previously,我有Visual Studio中抛出错误。这是一个
的ArgumentException
消息在异步
TaskScheduled事件中使用未定义的关键字值1。谷歌搜索没有露面任何解决方案。下面是code:
Geolocator定位器=新Geolocator();
Geoposition位置=等待Locator.GetGeopositionAsync();
会有地理座标坐标= Position.Coordinate;当我能得到抛出的错误,异常被抛出上面样本中的第二或第三线。
我简化了原来的code,试图修复它,但原来这就是:Geolocator定位器=新Geolocator();
会有地理座标坐标=(等待Locator.GetGeopositionAsync())Position.Coordinate。整个应用程序的工作原理时调试,但几乎崩溃,否则瞬间
这是Windows 8.1的通用项目,专注于手机项目。
在此先感谢
编辑:按照要求,这里是完整的方法:
私有静态布尔CheckConnection()
{
ConnectionProfile连接= NetworkInformation.GetInternetConnectionProfile();
布尔互联网连接= = NULL&放大器;!&安培; connections.GetNetworkConnectivityLevel()== NetworkConnectivityLevel.InternetAccess;
返回互联网;
}
公共静态异步任务<双> GetTemperature(布尔力)
{
如果(CheckConnection()||力)
{
Geolocator定位器=新Geolocator();
等待Task.Yield(); //此处出现错误
Geoposition位置=等待Locator.GetGeopositionAsync();
会有地理座标坐标= Position.Coordinate;
HttpClient的客户端=新的HttpClient();
双温;
乌里U =新Uri(string.Format(\"http://api.worldweatheronline.com/free/v1/weather.ashx?q={0},{1}&format=xml&num_of_days=1&date=today&cc=yes&key={2}\",
Coordinate.Point.Position.Latitude,
Coordinate.Point.Position.Longitude,
API密钥),
UriKind.Absolute);
串生=等待Client.GetStringAsync(U);
主要的XElement = XElement.Parse(RAW),current_condition,temp_c;
current_condition = main.Element(current_condition);
temp_c = current_condition.Element(temp_C);
温度= Convert.ToDouble(temp_c.Value);
开关(Memory.TempUnit)
{
情况下0:
温度= Convertions.Temperature.CelsiusToFahrenheit(温度);
打破;
案例2:
温度= Convertions.Temperature.CelsiusToKelvin(温度);
打破;
}
回水温度;
}
其他
{
抛出新的InvalidOperationException异常(无法连接到服务器的天气。);
}
}编辑2:我要求在Twitter上帮助和收到回复要求一个摄制项目。我重新创建原始应用的主要部分,但我无法得到错误。然而,你所以这里的项目。
修改3:如果有帮助可言,这里有异常的详细信息:
发生System.ArgumentException
_HResult = -2147024809
_message =使用事件TaskScheduled未定义的关键字的值1。
的HResult = -2147024809
IsTransient = FALSE
消息=事件TaskScheduled使用未定义的关键字的值1。
来源= mscorlib程序
堆栈跟踪:
在System.Diagnostics.Tracing.ManifestBuilder.GetKeywords(UINT64关键字,字符串eventName的)
的InnerException:
解决方案检查过<一个href=\"http://stackoverflow.com/questions/24747885/argumentexception-use-of-undefined-keyword-value-1-for-event-taskscheduled-in\">this和<一个href=\"https://social.msdn.microsoft.com/Forums/windowsapps/en-US/3e505e04-7f30-4313-aa47-275eaef333dd/systemargumentexception-use-of-undefined-keyword-value-1-for-event-taskscheduled-in-async?forum=wpdevelop\"相对=nofollow>这,我相信这是在<一个错误href=\"http://blogs.msdn.com/b/windowsappdev/archive/2012/04/24/diving-deep-with-winrt-and-await.aspx\"相对=nofollow>。NET
异步/的await
基础设施WinRT的。我不能瑞普它,但我建议您尝试以下解决方法,看它是否适合你。
因子所有异步调用awaitable从
的OnNavigatedTo
到一个单独的异步任务
的方法,例如ContinueAsync
:异步任务ContinueAsync()
{
Geolocator定位器=新Geolocator();
Geoposition位置=等待Locator.GetGeopositionAsync();
会有地理座标坐标= Position.Coordinate; // ... VAR messageDialog =新Windows.UI.Popups.MessageDialog(你好);
等待messageDialog.ShowAsync(); // ...
}
从
的OnNavigatedTo
删除异步
修改并调用ContinueAsync
从的OnNavigatedTo
是这样的:VAR调度= TaskScheduler.FromCurrentSynchronizationContext();
Task.Factory.StartNew(
()=&GT; ContinueAsync(),
CancellationToken.None,TaskCreationOptions.None,调度程序)。
展开()。
ContinueWith(T =&GT;
{
尝试
{
t.GetAwaiter()调用getResult()。
}
赶上(异常前)
{
的Debug.WriteLine(除息);
扔; //重新抛出或以某种方式处理
}
},
CancellationToken.None,
TaskContinuationOptions.NotOnRanToCompletion,
调度程序);
让我们知道,如果它可以帮助:)
更新,显然,这个bug是某处TPL记录提供商,<一个href=\"http://referencesource.microsoft.com/#mscorlib/system/threading/Tasks/TPLETWProvider.cs,e38cada0f78eafb7\"相对=nofollow>
TplEtwProvider
。你可以看到,如果你添加下面的code它变得创建。到目前为止,我无法找到一个方法来禁用该事件源(直接或通过反射):内部类MyEventListener:事件监听
{
保护覆盖无效OnEventSourceCreated(EventSource的EventSource的)
{
base.OnEventSourceCreated(EventSource的);
如果(eventSource.Name ==System.Threading.Tasks.TplEventSource)
{
启用变种= eventSource.IsEnabled(); //试图禁用 - 不支持的命令:(
System.Diagnostics.Tracing.EventSource.SendCommand(
EventSource的,EventCommand.Disable,新System.Collections.Generic.Dictionary&LT;字符串,字符串&GT;());
}
}
}// ...
公共密封部分类应用:应用
{
静态MyEventListener监听器=新MyEventListener();
}System Information
- Windows 10 Technical Preview (build 9926)
- Visual Studio Community 2013
Attempting to debug on:- [AT&T] Lumia 635 (Windows 10 Technical Preview for phones build 9941 w/ Lumia Cyan)
- [AT&T] Lumia 1520 (Windows Phone 8.1 with Lumia Denim and PfD)
- [Unlocked] BLU Win Jr (Windows Phone 8.1 with PfD)
- [Verizon] Lumia Icon (Windows Phone 8.1 with Lumia Denim and PfD)
I trying to get location services working in my app. Previously, I had Visual Studio throw the error. It was an
ArgumentException
with the message "Use of undefined keyword value 1 for event TaskScheduled in async
". Googling didn't turn up any solutions.Here is the code:
Geolocator Locator = new Geolocator(); Geoposition Position = await Locator.GetGeopositionAsync(); Geocoordinate Coordinate = Position.Coordinate;
When I could get the error to be thrown, the exception was thrown on the 2nd or 3rd line in the sample above. I simplified the original code to try and fix it, but this is the original:
Geolocator Locator = new Geolocator(); Geocoordinate Coordinate = (await Locator.GetGeopositionAsync()).Position.Coordinate;
The entire app works when debugging, but crashes almost instantaneously otherwise.
This is a Windows 8.1 Universal project, focusing on the phone project.
Thanks in advance
EDIT: As requested, here is the full method:
private static bool CheckConnection() { ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile(); bool internet = connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess; return internet; } public static async Task<double> GetTemperature(bool Force) { if (CheckConnection() || Force) { Geolocator Locator = new Geolocator(); await Task.Yield(); //Error occurs here Geoposition Position = await Locator.GetGeopositionAsync(); Geocoordinate Coordinate = Position.Coordinate; HttpClient Client = new HttpClient(); double Temperature; Uri u = new Uri(string.Format("http://api.worldweatheronline.com/free/v1/weather.ashx?q={0},{1}&format=xml&num_of_days=1&date=today&cc=yes&key={2}", Coordinate.Point.Position.Latitude, Coordinate.Point.Position.Longitude, "API KEY"), UriKind.Absolute); string Raw = await Client.GetStringAsync(u); XElement main = XElement.Parse(Raw), current_condition, temp_c; current_condition = main.Element("current_condition"); temp_c = current_condition.Element("temp_C"); Temperature = Convert.ToDouble(temp_c.Value); switch (Memory.TempUnit) { case 0: Temperature = Convertions.Temperature.CelsiusToFahrenheit(Temperature); break; case 2: Temperature = Convertions.Temperature.CelsiusToKelvin(Temperature); break; } return Temperature; } else { throw new InvalidOperationException("Cannot connect to the weather server."); } }
EDIT 2: I've asked for help on Twitter, and received a reply asking for a repro project. I recreated the major portion of the original app, but I could not get the error. However, errors may occur for you so here's the project.
EDIT 3: If it helps at all, here are the exception details:
System.ArgumentException occurred _HResult=-2147024809 _message=Use of undefined keyword value 1 for event TaskScheduled. HResult=-2147024809 IsTransient=false Message=Use of undefined keyword value 1 for event TaskScheduled. Source=mscorlib StackTrace: at System.Diagnostics.Tracing.ManifestBuilder.GetKeywords(UInt64 keywords, String eventName) InnerException:
解决方案Having checked this and this, I believe this is a bug in .NET
async/await
infrastructure for WinRT. I couldn't repro it, but I encourage you to try the following workaround, see if it works for you.
Factor out all asynchronous awaitable calls from
OnNavigatedTo
into a separateasync Task
method, e.g.ContinueAsync
:async Task ContinueAsync() { Geolocator Locator = new Geolocator(); Geoposition Position = await Locator.GetGeopositionAsync(); Geocoordinate Coordinate = Position.Coordinate; // ... var messageDialog = new Windows.UI.Popups.MessageDialog("Hello"); await messageDialog.ShowAsync(); // ... }
Remove
async
modifier fromOnNavigatedTo
and callContinueAsync
fromOnNavigatedTo
like this:var scheduler = TaskScheduler.FromCurrentSynchronizationContext(); Task.Factory.StartNew( () => ContinueAsync(), CancellationToken.None, TaskCreationOptions.None, scheduler). Unwrap(). ContinueWith(t => { try { t.GetAwaiter().GetResult(); } catch (Exception ex) { Debug.WriteLine(ex); throw; // re-throw or handle somehow } }, CancellationToken.None, TaskContinuationOptions.NotOnRanToCompletion, scheduler);
Let us know if it helps :)
Updated, apparently, the bug is somewhere in the TPL logging provider,
TplEtwProvider
. You can see it's getting created if you add the below code. So far, I couldn't find a way to disable this event source (either directly or via Reflection):internal class MyEventListener : EventListener { protected override void OnEventSourceCreated(EventSource eventSource) { base.OnEventSourceCreated(eventSource); if (eventSource.Name == "System.Threading.Tasks.TplEventSource") { var enabled = eventSource.IsEnabled(); // trying to disable - unsupported command :( System.Diagnostics.Tracing.EventSource.SendCommand( eventSource, EventCommand.Disable, new System.Collections.Generic.Dictionary<string, string>()); } } } // ... public sealed partial class App : Application { static MyEventListener listener = new MyEventListener(); }
这篇关于应用程序不会崩溃,调试,但正常运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!