[Mono-bugs] [Bug 50366][Wis] New - Delegate Bug - unregistering
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Thu, 30 Oct 2003 15:36:29 -0500 (EST)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by jasoncwarner@yahoo.com.
http://bugzilla.ximian.com/show_bug.cgi?id=50366
--- shadow/50366 2003-10-30 15:36:29.000000000 -0500
+++ shadow/50366.tmp.8306 2003-10-30 15:36:29.000000000 -0500
@@ -0,0 +1,145 @@
+Bug#: 50366
+Product: Mono/Runtime
+Version: unspecified
+OS: Red Hat 9.0
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Wishlist
+Component: misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: jasoncwarner@yahoo.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Delegate Bug - unregistering
+
+Simple Delegate Example:
+
+using System;
+
+namespace PhoneCallAttempt
+{
+ class Mother
+ {
+
+ public void Subscribe()
+ {
+ Daughter.OnPhoneCall += new
+Daughter.OnPhoneCallHandler(RecieveNotification);
+ Console.WriteLine("Mother has subscribed to call notification");
+ }
+
+ public void UnSubscribe()
+ {
+ Daughter.OnPhoneCall -= new
+Daughter.OnPhoneCallHandler(RecieveNotification);
+ Console.WriteLine("Mother has UNsubscribed to call notification");
+ }
+
+ public void RecieveNotification(object sender, EventArgs e)
+ {
+ Console.WriteLine("Mother has been notified of call placed");
+ }
+
+ }
+
+ class Father
+ {
+ public void Subscribe()
+ {
+ Daughter.OnPhoneCall += new
+Daughter.OnPhoneCallHandler(RecieveNotification);
+ Console.WriteLine("Father has subscribed to call notification");
+ }
+
+ public void UnSubscribe()
+ {
+ Daughter.OnPhoneCall -= new
+Daughter.OnPhoneCallHandler(RecieveNotification);
+ Console.WriteLine("Father has UNsubscribed to call notification");
+ }
+
+ public void RecieveNotification(object sender, EventArgs e)
+ {
+ Console.WriteLine("Father has been notified of call placed");
+ }
+
+ }
+
+ class Daughter
+ {
+
+ public delegate void OnPhoneCallHandler (object sender, EventArgs e);
+ public static event OnPhoneCallHandler OnPhoneCall;
+ public void PlaceCall()
+ {
+ Console.WriteLine("Daughter has placed a phone call");
+ if (OnPhoneCall != null)
+ {
+ EventArgs e = new EventArgs();
+ OnPhoneCall(this , e);
+ }
+ }
+
+ }
+
+ class Test
+ {
+
+ public static void Main()
+ {
+ Mother m = new Mother();
+ Father f = new Father();
+ Daughter d = new Daughter();
+
+ m.Subscribe();
+ f.Subscribe();
+ d.PlaceCall();
+
+ m.UnSubscribe();
+ f.UnSubscribe();
+ d.PlaceCall();
+
+ }
+ }
+}
+
+Steps to reproduce the problem:
+1. Copy code to file (filename.cs)
+2. compile (mcs filename.cs)
+3. Run (mint filename.exe)
+
+Actual Results:
+
+Mother has subscribed to call notification
+Father has subscribed to call notification
+Daughter has placed a phone call
+Mother has been notified of call placed
+Father has been notified of call placed
+Mother has UNsubscribed to call notification
+Father has UNsubscribed to call notification
+Daughter has placed a phone call
+Mother has been notified of call placed
+Father has been notified of call placed
+
+
+Expected Results:
+
+Mother has subscribed to call notification
+Father has subscribed to call notification
+Daughter has placed a phone call
+Mother has been notified of call placed
+Father has been notified of call placed
+Mother has UNsubscribed to call notification
+Father has UNsubscribed to call notification
+Daughter has placed a phone call
+
+How often does this happen?
+Every time I run it.
+
+Additional Information:
+
+Tested on windows with .NET and the code works.