[Gtk-sharp-list] Problem/bug using gtk# event handlers

Lee Mallabone gnome@fonicmonkey.net
30 Oct 2002 08:57:21 +0000


--=-dJGvsqlLL4kyww/XMxxS
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi,

I'm having trouble using Gtk# event handlers. All I want to do is remove
an existing event handler from a Button's "Clicked" event and then add a
different handler to the same event.

However, when I try and do that mono crashes with this error:

Unhandled Exception: System.ArgumentException: Key duplication
in <0x002ff> 00 System.Collections.Hashtable:PutImpl
(object,object,bool)
in <0x00018> 00 System.Collections.Hashtable:Add (object,object)
in <0x00051> 00 System.ComponentModel.EventHandlerList:AddHandler
(object,System.Delegate)
in <0x000d5> 00 Gtk.Button:add_Clicked (System.EventHandler)
in <0x000d2> 00 .eventtest:.ctor ()
in <0x00096> 00 .eventtest:Main (string[])

I've attached the simplest test case I could write that demonstrates
this behaviour. It's an over-simplification of a similar situation in my
real code.

The attached code crashes on startup with gtk# 0.4 and mono 0.15. Can
anyone tell me if this is known behaviour, a bug, or am I using the
handlers incorrectly?

Regards,

Lee Mallabone.


--=-dJGvsqlLL4kyww/XMxxS
Content-Disposition: attachment; filename=eventtest.cs
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=eventtest.cs; charset=ISO-8859-1


using System;
using Gtk;
using Gnome;

public class eventtest : App
{

=A0private void TestHandler(object sender, System.EventArgs args)
=A0{
=A0=A0=A0=A0=A0=A0=A0=A0Console.WriteLine("event handled!");
=A0}
=A0
=A0public eventtest(): base ("test", "event test")
=A0{
=A0=A0=A0=A0=A0=A0=A0=A0Button testButton =3D new Button("Test button");
=A0=A0=A0=A0=A0=A0=A0=A0testButton.Clicked +=3D new EventHandler(TestHandle=
r);
=A0=A0=A0=A0=A0=A0=A0=A0testButton.Clicked -=3D new EventHandler(TestHandle=
r);
=A0=A0=A0=A0=A0=A0=A0=A0testButton.Clicked +=3D new EventHandler(TestHandle=
r);
=A0}
=A0
=A0public static int Main(string[] args)
=A0{
=A0=A0=A0=A0=A0=A0=A0=A0Program eventTest =3D new Program("eventTest", "0.1=
", Modules.UI, args);
=A0=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0new eventtest().ShowAll();
=A0=A0=A0=A0=A0=A0=A0=A0eventTest.Run();
=A0=A0=A0=A0=A0=A0=A0=A0return 0;
=A0}
}

--=-dJGvsqlLL4kyww/XMxxS--