[Mono-dev] StackOverflow on System.Delegate.Equals
Alan
alan.mcgovern at gmail.com
Mon Apr 4 18:05:11 EDT 2011
Hey,
Well the other thing is that the delegate class is supposed to be
immutable. Therefore it should be impossible to produce a corrupt
delegate through multithreaded access as any modification to a
delegate instance results in a new copy of the delegate (with
modification) being created, just like for string operations. If what
we're seeing is truly a corrupt delegate instance then it's a bug in
mono that this is able to occur.
Alan
On Mon, Apr 4, 2011 at 10:54 PM, <kralu at poczta.onet.pl> wrote:
> On Mon, 2011-04-04 22:41:47 nekresh <nekresh at gmail.com> wrote:
>> On Mon, Apr 4, 2011 at 10:37 PM, <kralu at poczta.onet.pl> wrote:
>> > On Mon, 2011-04-04 22:03:47 Gonzalo Paniagua Javier <gonzalo.mono at gmail.com> wrote:
>> >> On Mon, 2011-04-04 at 20:48 +0100, Alan wrote:
>> >> > Aren't event handler methods emitted with a [synchronized] attribute
>> >> > by default which would prevent this issue? You can check by
>> >> > disassembling the IL and seeing if its there.
>> >>
>> >> They are synchronized as long as you don't replace the default
>> >> add/remove with your own code.
>> >
>> > AFAIK you cannot inherit from the Delegate/MulticastDelegate class. So how can I replace the default add/remove code? Anyway I'm almost sure that case has no place in my code but I have to take a look on 3rd part libraries. Thanks in advance for any help.
>> >
>> public event MyType MyEvent {
>> add { }
>> remove { }
>> }
>
> Ok, thanks. I found in Telerik's code a few places where code looks like:
> public event XmlHttpPanelEventHandler ServiceRequest
> {
> add
> {
> base.Events.AddHandler(WebServiceRequestEvent, value);
> }
> remove
> {
> base.Events.RemoveHandler(WebServiceRequestEvent, value);
> }
> }
>
> The base.Events is a property of the WebControl class. Maybe that's the problem?
> I've also took a look on a code generated for a "default" event handler (from my class):
>
> internal event EventHandler<MenuItemClickedEventArgs> ItemClicked
> {
> add
> {
> EventHandler<MenuItemClickedEventArgs> handler2;
> EventHandler<MenuItemClickedEventArgs> itemClicked = this.ItemClicked;
> do
> {
> handler2 = itemClicked;
> EventHandler<MenuItemClickedEventArgs> handler3 = (EventHandler<MenuItemClickedEventArgs>) Delegate.Combine(handler2, value);
> itemClicked = Interlocked.CompareExchange<EventHandler<MenuItemClickedEventArgs>>(ref this.ItemClicked, handler3, handler2);
> }
> while (itemClicked != handler2);
> }
> remove
> {
> EventHandler<MenuItemClickedEventArgs> handler2;
> EventHandler<MenuItemClickedEventArgs> itemClicked = this.ItemClicked;
> do
> {
> handler2 = itemClicked;
> EventHandler<MenuItemClickedEventArgs> handler3 = (EventHandler<MenuItemClickedEventArgs>) Delegate.Remove(handler2, value);
> itemClicked = Interlocked.CompareExchange<EventHandler<MenuItemClickedEventArgs>>(ref this.ItemClicked, handler3, handler2);
> }
> while (itemClicked != handler2);
> }
> }
>
>
> Kind regards,
> Marcin
>
>
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
More information about the Mono-devel-list
mailing list