事件函数块的返回值https://msdn.microsoft.com论述

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的。

关键词:

事件处理函数队列,同步执行处理函数的存在先后顺序,具有出参和返回值声明的事件,不太适合做验证类型的业务。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值