[Gtk-sharp-list] bug: Removing event handlers

Lee Mallabone gnome@fonicmonkey.net
05 Feb 2003 09:40:57 -0500

Content-Type: text/plain
Content-Transfer-Encoding: 7bit


I've found what I think is a bug with removing event handlers in

When I use:

button.Clicked -= new EventHandler(handler1);

the handler is not actually removed, and still receives events from the

I've attached a small test case that demonstrates this behaviour - after
switching event handlers on a button, both the old and the new handlers
are fired rather than just the new handler.

Could anyone please comment on whether they can reproduce this? I'm
using RedHat 8.0 with mono 0.19 and Gtk# 0.7.

I've opened a bug on bugzilla.ximian.com to track this, (bug #37635),
but thought I'd post here in case there's some magic quick fix I'm just
not seeing. :)


Lee Mallabone <gnome@fonicmonkey.net>

Content-Disposition: attachment; filename=eventtest.cs
Content-Type: text/plain; name=eventtest.cs; charset=ANSI_X3.4-1968
Content-Transfer-Encoding: 7bit

using System;
using Gtk;

public class eventtest : Window
 private Button testButton;
 public eventtest(): base ("event test")
  	// Make a button for the test event handlers
  	testButton = new Button("Test button");
	testButton.Clicked += new EventHandler(TestHandler1);
	// Make a button to change event handlers on the other button
	Button eventSwitcher = new Button("Change event handler");
	eventSwitcher.Clicked += new EventHandler(EventSwitcher);
	// Add the buttons to the window
	HBox box = new HBox(true, 5);

 ////////// Event handlers /////////
 private void TestHandler1(object sender, EventArgs args)
  	Console.WriteLine("event handled with handler 1!");
 private void TestHandler2(object sender, EventArgs args)
  	Console.WriteLine("event handled with handler 2!");

 private void EventSwitcher(object sender, EventArgs args)
	testButton.Clicked -= new EventHandler(TestHandler1);
	testButton.Clicked += new EventHandler(TestHandler2);

 // Initialisation
 public static int Main(string[] args)
  	new eventtest().ShowAll();
	return 0;