您的位置:首页 > 理论基础 > 计算机网络

事件函数块的返回值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的。

关键词:

事件处理函数队列,同步执行处理函数的存在先后顺序,具有出参和返回值声明的事件,不太适合做验证类型的业务。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C# .net 函数