[Mono-bugs] [Bug 59379][Maj] New - Sustem.Threading.Timer hangs while disposing

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 1 Jun 2004 02:52:16 -0400 (EDT)


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 azabytin@mera.ru.

http://bugzilla.ximian.com/show_bug.cgi?id=59379

--- shadow/59379	2004-06-01 02:52:16.000000000 -0400
+++ shadow/59379.tmp.21579	2004-06-01 02:52:16.000000000 -0400
@@ -0,0 +1,108 @@
+Bug#: 59379
+Product: Mono: Class Libraries
+Version: unspecified
+OS: Red Hat 9.0
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: azabytin@mera.ru               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Sustem.Threading.Timer hangs while disposing
+
+Timer hangs while disposing
+
+Steps to reproduce the problem:
+1. Compile example ( see Additional Information)
+2. Run example, it will hangs after "disposing of timer..." message
+
+Actual Results:
+
+10:05:43.4703290 Checking Status 1.
+10:05:44.5626170 Checking Status 2.
+10:05:45.5825240 Checking Status 3.
+10:05:46.5925250 Checking Status 4.
+10:05:47.6026080 Checking Status 5.
+changed...
+10:05:57.6135120 Checking Status 6.
+10:05:57.7233620 Checking Status 7.
+10:05:57.8333970 Checking Status 8.
+10:05:57.9434310 Checking Status 9.
+10:05:58.0533840 Checking Status 10.
+disposing of timer...
+
+
+Expected Results:
+
+0:51:40.5809015 Checking Status 1.
+10:51:41.5823515 Checking Status 2.
+10:51:42.5838015 Checking Status 3.
+10:51:43.5852515 Checking Status 4.
+10:51:44.5867015 Checking Status 5.
+changed...
+10:51:54.5911870 Checking Status 6.
+10:51:54.6913320 Checking Status 7.
+10:51:54.7914770 Checking Status 8.
+10:51:54.8916220 Checking Status 9.
+10:51:54.9917670 Checking Status 10.
+disposing of timer...
+Timer example done.
+
+How often does this happen? 
+Always
+
+Additional Information:
+
+Source code to reproduce the problem:
+
+using System;
+using System.Threading;
+
+class TimerExampleState {
+    public int counter = 0;
+    public Timer tmr;
+}
+
+class App {
+   public static void Main() {
+    TimerExampleState s = new TimerExampleState();
+
+    // Create the delegate that invokes methods for the timer.
+    TimerCallback timerDelegate = new TimerCallback(CheckStatus);
+
+    // Create a timer that waits one second, then invokes every second.
+    Timer timer = new Timer(timerDelegate, s,1000, 1000);
+    
+    // Keep a handle to the timer, so it can be disposed.
+    s.tmr = timer;
+
+    // The main thread does nothing until the timer is disposed.
+    while (s.tmr != null)
+        Thread.Sleep(0);
+    Console.WriteLine("Timer example done.");
+   }
+   // The following method is called by the timer's delegate.
+
+   static void CheckStatus(Object state) {
+    TimerExampleState s = (TimerExampleState) state;
+    s.counter++;
+          Console.WriteLine("{0} Checking Status {1}.",DateTime.Now.
+TimeOfDay, s.counter);
+        if (s.counter == 5) {
+        // Shorten the period. Wait 10 seconds to restart the timer.
+        (s.tmr).Change(10000,100);
+        Console.WriteLine("changed...");
+    }
+        if (s.counter == 10) {
+        Console.WriteLine("disposing of timer...");
+        s.tmr.Dispose();
+        s.tmr = null;
+    }
+   }
+}