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的。
关键词:
事件处理函数队列,同步执行处理函数的存在先后顺序,具有出参和返回值声明的事件,不太适合做验证类型的业务。
版权声明:本文为博主原创文章,未经博主允许不得转载。
事件函数块的返回值https://msdn.microsoft.com论述
原文地址:http://blog.csdn.net/jk_yang/article/details/48023667