ArgumentException的 - 使用未定义的关键字值1的事件TaskScheduled在异步 [英] ArgumentException - Use of undefined keyword value 1 for event TaskScheduled in async

查看:292
本文介绍了ArgumentException的 - 使用未定义的关键字值1的事件TaskScheduled在异步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获取System.ArgumentException - 使用未定义的关键字值1条,在异步API的TaskScheduled事件



有运行在通用应用第一的await语句时有些不妥与Visual Studio 2013更新3。



我使用WP8.1环球和Silverlight应用程序我安装后的Visual Studio 2013更新3。



例外发生在模拟器/设备模式。我花了几天时间研究此问题没有任何解决方案。



我在Windows开发人员中心论坛的兄弟姐妹文章,但我没有听到任何来自Microsoft的答案。



该代码是直线前进。一旦内部异常被抛出,AWAIT永不再来。



是其他任何人有这些问题与异步? ?决议

 公共异步任务< StorageFolder> FolderExists(StorageFolder父母,串FOLDERNAME)
{
StorageFolder结果= NULL;

{
//异常发生在这里。不会返回代码,使线程挂起
结果=等待parent.GetFolderAsync(文件夹名);
}
赶上(异常前)
{
如果(FeishLogger.Logger.IsDebug)
ex.LogException(()=>的String.Format(FolderExists文件:{0} \\ {1},parent.Path,FOLDERNAME));
}

返回结果;
}

完整的异常:

  System.ArgumentException发生
_HResult = -2147024809
_message =使用事件TaskScheduled未定义的关键字的值1。
HResult的= -2147024809
IsTransient = FALSE
消息事件TaskScheduled =使用未定义的关键字的值1。
来源= mscorlib程序
堆栈跟踪:在System.Diagnostics.Tracing.ManifestBuilder.GetKeywords
(UINT64关键字,字符串eventName的)
的InnerException:

我有一个示例项目可用。创建一个shell通用的应用程序,并增加了一些等待语句使问题reocur。

 专用异步任务AsyncMethod()
{
的Debug.WriteLine(({0:0000} - 同步调试),Environment.CurrentManagedThreadId);

//取消注释此行,使其工作
//等待Task.Delay(1);

//失败只有在上述行被注释
等待Task.Run(()=>的Debug.WriteLine(({0:0000} - 异步调试)环境.CurrentManagedThreadId));
}





下面是到AsyncMethod电话



全OnLaunched代码

 保护覆盖异步无效OnLaunched(LaunchActivatedEventArgs E)
{
#如果DEBUG
如果(System.Diagnostics.Debugger.IsAttached)
{
this.DebugSettings.EnableFrameRateCounter = TRUE;
}
#ENDIF

帧rootFrame = Window.Current.Content的框架;

//不要重复应用初始化时,窗口已经有内容,
//只是确保窗口是活动的
如果(rootFrame == NULL)
{
//创建一个框架来充当导航上下文并导航到第一页
rootFrame =新帧();

// TODO:此值更改为高速缓存的大小是否适合您的应用程序
rootFrame.CacheSize = 1;

如果(e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
// TODO:负荷状态从先前暂停的应用程序
}

//放置在当前窗口
Window.Current.Content = rootFrame帧;
}

如果(rootFrame.Content == NULL)
{
#如果WINDOWS_PHONE_APP
//移除启动时的检票口导航。
如果(rootFrame.ContentTransitions!= NULL)
{
this.transitions =新TransitionCollection();
的foreach(在rootFrame.ContentTransitions变种C)
{
this.transitions.Add(C);
}
}

rootFrame.ContentTransitions = NULL;
rootFrame.Navigated + = this.RootFrame_FirstNavigated;
#ENDIF

等待AsyncMethod();

等待AsyncMethods();
等待AsyncMethods();
等待AsyncMethods();


//当导航堆栈不被需要传递的信息作为导航
恢复导航到第一页,
//配置新页/ /参数
如果(rootFrame.Navigate(typeof运算(的MainPage),e.Arguments)!)
{
抛出新的异常(无法创建初始页);
}
}

//确保当前窗口被激活
Window.Current.Activate();
}


解决方案

的异常可以忽略不计。刚打戏。另外,您可以在调试异常禁用突破 - >例外菜单



在这里输入的形象描述


Getting System.ArgumentException - Use of undefined keyword value 1 for event TaskScheduled in async apis.

There is something wrong when running the first await statement in an Universal app with Visual Studio 2013 Update 3.

I am using WP8.1 Universal and silverlight apps after I installed Visual Studio 2013 Update 3.

The exceptions happens in Emulator/Device modes. I have spent a couple of days researching this issue without any resolution.

I have a sibling article at Windows Dev center forum but I have not heard any answers from Microsoft.

The code is straight forward. Once the internal exception is thrown, the await never returns.

Is anyone else having these issues with async ?? resolution ?

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;
}

Full exception:

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: 

I have a sample project available. Creating a shell Universal App and adding some await statement makes the problem reocur.

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));
}

Here is the full OnLaunched code with calls to AsyncMethod

   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();
    }

解决方案

The exception can be ignored. Just hit play. Alternatively you can disable break on exceptions in debug -> exceptions menu.

这篇关于ArgumentException的 - 使用未定义的关键字值1的事件TaskScheduled在异步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆