multicastdelegate

Why delegate types are derived from MulticastDelegate class why not it directly derive from Delegate class?

醉酒当歌 提交于 2020-01-03 17:25:14
问题 I have a very basic question regarding delegate types. I compared the memebers of Delegate and MulticastDelegate classes in object browser and I couldn't find any new additional member present in MulticastDelegate. I also noticed that the Delegate class has GetInvocationList virtual method. So I assume that the Delegate class should have the capability to hold references to multiple methods. If my assumption is correct I wonder why not custom delegate types directly derive from the Delegate

Why delegate types are derived from MulticastDelegate class why not it directly derive from Delegate class?

[亡魂溺海] 提交于 2020-01-03 17:25:10
问题 I have a very basic question regarding delegate types. I compared the memebers of Delegate and MulticastDelegate classes in object browser and I couldn't find any new additional member present in MulticastDelegate. I also noticed that the Delegate class has GetInvocationList virtual method. So I assume that the Delegate class should have the capability to hold references to multiple methods. If my assumption is correct I wonder why not custom delegate types directly derive from the Delegate

Signals and slots implementation in Delphi?

纵饮孤独 提交于 2019-12-19 09:04:04
问题 Does an implementation of the signals and slots mechanism for event dispatching exist for Delphi? 回答1: Search for multicast events. There are a few implementations out there, e.g. http://www.deltics.co.nz/blog/?p=137 http://blogs.embarcadero.com/abauer/2008/09/03/38867 http://www.codebot.org/delphi/?doc=9568 Some of them need generics, so are D>2009 only. 回答2: Whilst you can implement multi-cast events yourself, they are not directly supported in the the language unlike in C# and VB.NET. Lack

Is there a Delegate which isn't a MulticastDelegate in C#?

别来无恙 提交于 2019-12-18 04:49:08
问题 I think the answer is NO? If there isn't, why do we have separated Delegate and MulticastDelegate classes? Maybe it's again because of "some other .NET languages"? 回答1: EDIT: I thought this was part of ECMA 335, but I can't see it in there anywhere. You can't create such a delegate type in C#, but you can in IL: .class public auto ansi sealed Foo extends [mscorlib]System.Delegate { // Body as normal } The C# compiler has no problems using such a delegate: using System; class Test { static

Are `System.MulticastDelegate`'s thread-safe?

南笙酒味 提交于 2019-12-11 08:53:32
问题 I'm looking for someone that might know more about this, my gut tells me that the answer is "no, it is not thread-safe" but I want to be sure. In order to illustrate my question, I have provided some context with this class public class MyContext { private readonly object _lock = new object(); public delegate bool MyDelegate(MyContext context); private MyDelegate _multicastDelegate; public MyContext() { _multicastDelegate = null; } public void AddDelegate(MyDelegate del) { lock(_lock) {

Using MulticastDelegate as parameter while avoiding DynamicInvoke

对着背影说爱祢 提交于 2019-12-04 11:54:18
I have a MulticastDelegate that can reference one of a number of (legacy) delegates that have the same signature. For example: public delegate void ObjectCreated(object sender, EventArgs args); public delegate void ObjectDeleted(object sender, EventArgs args); //... Those delegates are then used to define events: public event ObjectCreated ObjectWasCreated; public event ObjectDeleted ObjectWasDeleted; I then have a method which takes in a MulticastDelegate that I use to do some common checking: void DispatchEvent(MulticastDelegate handler, object sender, EventArgs args) { if (handler != null)

How to handle exception in multicast delegate in C#?

▼魔方 西西 提交于 2019-12-01 07:31:50
I've been given some code that I am calling through multicast delegate. I would like to know how I can catch up and manage any exception raised there and that is not managed for the moment. I cannot modify the code given. I've been looking around and found about the need to call GetInvocationList() but not really sure if this is helpful. Consider the code using GetInvocationList : foreach (var handler in theEvent.GetInvocationList().Cast<TheEventHandler>()) { // handler is then of the TheEventHandler type try { handler(sender, ...); } catch (Exception ex) { // uck } } This my old approach, the

Signals and slots implementation in Delphi?

青春壹個敷衍的年華 提交于 2019-12-01 06:26:07
Does an implementation of the signals and slots mechanism for event dispatching exist for Delphi? Search for multicast events. There are a few implementations out there, e.g. http://www.deltics.co.nz/blog/?p=137 http://blogs.embarcadero.com/abauer/2008/09/03/38867 http://www.codebot.org/delphi/?doc=9568 Some of them need generics, so are D>2009 only. Whilst you can implement multi-cast events yourself, they are not directly supported in the the language unlike in C# and VB.NET. Lack of language support makes any attempt to emulate multi-cast events rather clumsy. Interestingly, C++ lacks

How to handle exception in multicast delegate in C#?

南楼画角 提交于 2019-12-01 05:22:16
问题 I've been given some code that I am calling through multicast delegate. I would like to know how I can catch up and manage any exception raised there and that is not managed for the moment. I cannot modify the code given. I've been looking around and found about the need to call GetInvocationList() but not really sure if this is helpful. 回答1: Consider the code using GetInvocationList : foreach (var handler in theEvent.GetInvocationList().Cast<TheEventHandler>()) { // handler is then of the

Multicast Delegates must have a return type of void. Why?

拜拜、爱过 提交于 2019-11-30 20:15:49
Multicast Delegates must have a return type of void Otherwise it will throw an exception. I want to know whats the reason behind it, what if multiple methods could have a same return type as of a delegate ? The premise is wrong; it works fine: Func<int> func = delegate { Console.WriteLine("first part"); return 5; }; func += delegate { Console.WriteLine("second part"); return 7; }; int result = func(); That is a multicast delegate with a non-void result, working fine. You can see from the console that both parts executed. The result of the last item is the one returned. We can demonstrate that