
获取异步任务的唯一标识符。
命名空间: System.ComponentModel
程序集: System(在 System.dll 中)
类型:System..::.Object唯一标识异步任务的对象引用;如果未设置任何值,则为 nullnothingnullptrnull 引用(在 Visual Basic 中为 nothing)。
备注 如果类支持多个异步方法或对单个方法的多次调用,则可以通过检查 UserState 属性的值确定哪个任务引发了 Methodname Completed 事件。当标记(称为任务 ID)对应的异步任务开始和完成时,您的代码需要跟踪这些标记。此属性的值是在对启动任务的异步方法进行初始调用时设置的。
示例
下面的代码示例演示如何使用 AsyncOperation 来跟踪异步 *** 作的生存期。此代码示例摘自一个为 System.ComponentModel..::.AsyncOperationManager 类提供的更大的示例。
using System;using System.Collections;using System.Collections.Specialized;using System.ComponentModel;using System.Data;using System.Drawing;using System.Globalization;using System.Threading;using System.windows.Forms;...// This event handler updates the ListVIEw control when the// PrimeNumberCalculator raises the CalculatePrimeCompleted// event. The ListVIEw item is updated with the appropriate// outcome of the calculation: Canceled,Error,or result.private voID primeNumberCalculator1_CalculatePrimeCompleted( object sender,CalculatePrimeCompletedEventArgs e){ GuID taskID = (GuID)e.UserState; if (e.Cancelled) { string result = "Canceled"; ListVIEwItem lvi = UpdateListVIEwItem(taskID,result); if (lvi != null) { lvi.Backcolor = color.Pink; lvi.Tag = null; } } else if (e.Error != null) { string result = "Error"; ListVIEwItem lvi = UpdateListVIEwItem(taskID,result); if (lvi != null) { lvi.Backcolor = color.Red; lvi.Forecolor = color.White; lvi.Tag = null; } } else { bool result = e.IsPrime; ListVIEwItem lvi = UpdateListVIEwItem( taskID,result,e.Firstdivisor); if (lvi != null) { lvi.Backcolor = color.lightGray; lvi.Tag = null; } }} 摘自MSDN: http://technet.microsoft.com/zh-cn/magazine/system.componentmodel.asynccompletedeventargs.userstate%28VS.90%29.aspx 总结
以上是内存溢出为你收集整理的silverlight 中的 userState 参数全部内容,希望文章能够帮你解决silverlight 中的 userState 参数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)