正在获取System.ArgumentException -在异步apis中为event TaskScheduled使用了未定义的关键字值1。
使用Visual Studio 2013 Update 3在通用应用程序中运行第一个等待语句时出现错误。
在安装Visual Studio 2013 Update 3之后,我正在使用WP8.1 Universal和silverlight应用程序。
在Emulator/Device模式下会发生异常。我花了几天的时间研究这个问题,但没有任何解决方案。
我在Windows开发人员中心论坛上有一篇兄弟文章,但我还没有从微软那里听到任何答复。
代码很简单。一旦抛出内部异常,await就再也不会返回。
还有其他人有这些异步问题吗??解决方案?
public async Task<StorageFolder> FolderExists(StorageFolder parent, string folderName)
{
StorageFolder result = null;
try
{
// Exception happens here. The code never returns so the thread hangs
result = await parent.GetFolderAsync(folderName);
}
catch (Exception ex)
{
if (FeishLogger.Logger.IsDebug)
ex.LogException(() => string.Format("FolderExists File: {0}\\{1}", parent.Path, folderName));
}
return result;
}
完全例外:
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:
我有一个可用的示例项目。创建一个shell通用应用程序并添加一些await语句会使问题再次出现。
private async Task AsyncMethod()
{
Debug.WriteLine("({0:0000} - Sync Debug)", Environment.CurrentManagedThreadId);
// Uncomment this line to make it work
//await Task.Delay(1);
// Fails only if the line above is commented
await Task.Run(() => Debug.WriteLine("({0:0000} - Async Debug)", Environment.CurrentManagedThreadId));
}
下面是调用AsyncMethod的完整OnLaunched代码
protected override async void OnLaunched(LaunchActivatedEventArgs e)
{
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
this.DebugSettings.EnableFrameRateCounter = true;
}
#endif
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
// TODO: change this value to a cache size that is appropriate for your application
rootFrame.CacheSize = 1;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
// TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
#if WINDOWS_PHONE_APP
// Removes the turnstile navigation for startup.
if (rootFrame.ContentTransitions != null)
{
this.transitions = new TransitionCollection();
foreach (var c in rootFrame.ContentTransitions)
{
this.transitions.Add(c);
}
}
rootFrame.ContentTransitions = null;
rootFrame.Navigated += this.RootFrame_FirstNavigated;
#endif
await AsyncMethod();
await AsyncMethods();
await AsyncMethods();
await AsyncMethods();
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
{
throw new Exception("Failed to create initial page");
}
}
// Ensure the current window is active
Window.Current.Activate();
}
发布于 2014-08-10 04:28:04
可以忽略该异常。只要点击播放即可。或者,您可以在debug -> exceptions菜单中禁用break on exceptions。
发布于 2015-09-01 08:48:44
这个问题仍然存在,正如另一个答案所说,异常本身可以被忽略。但如果异步操作包含在try/catch中,则会捕获异常,并且不会执行同一try/catch括号中的其他操作,这就是问题所在。
只要把这个放在异步操作之前就会变得更好。
try
{
await Task.Delay(1);
}
catch
{
// do nothing
}
异常仍然发生在Task.Delay(1)上,但之后它不会在随后的异步操作中发生。
发布于 2015-06-21 10:27:00
我解决这个问题的方法是
using System.Runtime.InteropServices.WindowsRuntime;
请勿删除此行。自动的"sort and remove usings“将(在我的例子中)删除它,导致这个隐秘的问题。不,我不知道为什么。但我知道这就是原因。
https://stackoverflow.com/questions/24747885
复制相似问题