事件函数块的返回值https://msdn.microsoft.com论述
2015-08-27 10:53
507 查看
REF:https://msdn.microsoft.com
Event Summary
When an event has multiple subscribers,
the event handlers are invoked synchronously when an event is raised. To
invoke events asynchronously, see Calling
Synchronous Methods Asynchronously.
下面讲述我遇到的引发事件时,同步调用多个处理程序的返回值现象。
场景:
public delegate bool PreValidateHandle(out string error_detail);
public event PreValidateHandle PreValidated;
bool fun1(out string error_detail)
{
error_detail = "fun1 error detail.";
return true;
}
bool fun2(out string error_detail)
{
error_detail = "fun2 error detail.";
return false;
}
static void Main()
{
PreValidated += fun1;
PreValidated += fun2;
string error_detail;
bool isValidated = PreValidated(out error_detail);
Question 1: isValidated == true?
Question 2: error_detail == "fun2 error detail."?
}
测试与结论:
出参error_detail和返回值,只能获取到fun2的。
关键词:
事件处理函数队列,同步执行处理函数的存在先后顺序,具有出参和返回值声明的事件,不太适合做验证类型的业务。
Event Summary
When an event has multiple subscribers,
the event handlers are invoked synchronously when an event is raised. To
invoke events asynchronously, see Calling
Synchronous Methods Asynchronously.
下面讲述我遇到的引发事件时,同步调用多个处理程序的返回值现象。
场景:
public delegate bool PreValidateHandle(out string error_detail);
public event PreValidateHandle PreValidated;
bool fun1(out string error_detail)
{
error_detail = "fun1 error detail.";
return true;
}
bool fun2(out string error_detail)
{
error_detail = "fun2 error detail.";
return false;
}
static void Main()
{
PreValidated += fun1;
PreValidated += fun2;
string error_detail;
bool isValidated = PreValidated(out error_detail);
Question 1: isValidated == true?
Question 2: error_detail == "fun2 error detail."?
}
测试与结论:
出参error_detail和返回值,只能获取到fun2的。
关键词:
事件处理函数队列,同步执行处理函数的存在先后顺序,具有出参和返回值声明的事件,不太适合做验证类型的业务。
相关文章推荐
- c#调用COM组件
- Mootools 1.2教程 函数
- autoit InputBox 函数
- 文件遍历排序函数
- C#实现把指定数据写入串口
- C#中抽象方法与虚拟方法的区别
- c#中虚函数的相关使用方法
- C#使用加边法计算行列式的值
- C#实现多线程的同步方法实例分析
- C#中尾递归的使用、优化及编译器优化
- C#通用邮件发送类分享
- C#中this的用法集锦
- C#.NET获取拨号连接的宽带连接方法
- C#实现AddRange为数组添加多个元素的方法
- C#中Equality和Identity浅析
- C#生成饼形图及添加文字说明实例代码
- C#判等对象是否相等的方法汇总
- C#简单的向量用法实例教程
- C#实现基于链表的内存记事本实例