From 74cee0a54f52a5a450fbde8cf48f585827adb512 Mon Sep 17 00:00:00 2001 From: Andreas N Date: Thu, 10 Jul 2003 16:55:22 +0000 Subject: 2003-07-10 Andreas Nahr * SystemEvents.cs: Implemented preliminary timer support, added private constructor, fixed events svn path=/trunk/mcs/; revision=16106 --- mcs/class/System/Microsoft.Win32/ChangeLog | 4 + mcs/class/System/Microsoft.Win32/SystemEvents.cs | 243 +++++++++++++---------- 2 files changed, 141 insertions(+), 106 deletions(-) (limited to 'mcs/class/System/Microsoft.Win32') diff --git a/mcs/class/System/Microsoft.Win32/ChangeLog b/mcs/class/System/Microsoft.Win32/ChangeLog index 78c9eaca5e5..166c27d2a89 100644 --- a/mcs/class/System/Microsoft.Win32/ChangeLog +++ b/mcs/class/System/Microsoft.Win32/ChangeLog @@ -1,3 +1,7 @@ +2003-07-10 Andreas Nahr + + * SystemEvents.cs: Implemented preliminary timer support, added private constructor, fixed events + 2003-06-12 Duncan Mak * UserPreferenceChangedEventArgs.cs diff --git a/mcs/class/System/Microsoft.Win32/SystemEvents.cs b/mcs/class/System/Microsoft.Win32/SystemEvents.cs index 1abc7aedf83..b0c43909d98 100644 --- a/mcs/class/System/Microsoft.Win32/SystemEvents.cs +++ b/mcs/class/System/Microsoft.Win32/SystemEvents.cs @@ -1,110 +1,141 @@ -// -// SystemEvents.cs -// -// Author: -// Johannes Roith (johannes@jroith.de) -// -// (C) 2002 Johannes Roith -// +// +// Microsoft.Win32.SystemEvents.cs +// +// Authors: +// Johannes Roith (johannes@jroith.de) +// Andreas Nahr (ClassDevelopment@A-SoftTech.com) +// +// (C) 2002 Johannes Roith +// (C) 2003 Andreas Nahr +// + +using System; +using System.Timers; +using System.Collections; -namespace Microsoft.Win32 { - /// - /// -public sealed class SystemEvents { - - [MonoTODO] - public static void InvokeOnEventsThread(System.Delegate method) - { - throw new System.NotImplementedException (); - } - - - - [MonoTODO] - public static event System.EventHandler DisplaySettingsChanged { - add { throw new System.NotImplementedException ();} - remove { throw new System.NotImplementedException ();} - } - - - [MonoTODO] - public static event System.EventHandler EventsThreadShutdown { - add { throw new System.NotImplementedException ();} - remove { throw new System.NotImplementedException ();} - } - - - [MonoTODO] - public static event System.EventHandler InstalledFontsChanged { - add { throw new System.NotImplementedException ();} - remove { throw new System.NotImplementedException ();} - } - - - [MonoTODO] - public static event System.EventHandler LowMemory { - add { throw new System.NotImplementedException ();} - remove { throw new System.NotImplementedException ();} - } - - - [MonoTODO] - public static event System.EventHandler PaletteChanged { - add { throw new System.NotImplementedException ();} - remove { throw new System.NotImplementedException ();} - } - - - [MonoTODO] - public static event PowerModeChangedEventHandler PowerModeChanged { - add { throw new System.NotImplementedException ();} - remove { throw new System.NotImplementedException ();} - } - - - [MonoTODO] - public static event SessionEndedEventHandler SessionEnded { - add { throw new System.NotImplementedException ();} - remove { throw new System.NotImplementedException ();} - } - - - [MonoTODO] - public static event System.EventHandler SessionEnding { - add { throw new System.NotImplementedException ();} - remove { throw new System.NotImplementedException ();} - } - - - [MonoTODO] - public static event System.EventHandler TimeChanged { - add { throw new System.NotImplementedException ();} - remove { throw new System.NotImplementedException ();} - } - - - [MonoTODO] - public static event UserPreferenceChangedEventHandler TimerElapsed { - add { throw new System.NotImplementedException ();} - remove { throw new System.NotImplementedException ();} - } - - - [MonoTODO] - public static event UserPreferenceChangedEventHandler UserPreferenceChanged { - add { throw new System.NotImplementedException ();} - remove { throw new System.NotImplementedException ();} - } - - - [MonoTODO] - public static event UserPreferenceChangingEventHandler UserPreferenceChanging { - add { throw new System.NotImplementedException ();} - remove { throw new System.NotImplementedException ();} - } - - -} +namespace Microsoft.Win32 +{ + public sealed class SystemEvents + { + private static Hashtable TimerStore = new Hashtable (); + + private SystemEvents () + { + } + + // You can use timers using the CreateTimer, KillTimer methods and the Timerelapsed event + // This is only a partial solution, as it only works in managed code. + // TODO implement this on OS level + // Till done this solution should work if you are only using the mentioned members + + public static IntPtr CreateTimer (int interval) + { + Guid Ident = Guid.NewGuid (); + int IdentValue = Ident.GetHashCode (); + Timer t = new System.Timers.Timer (interval); + t.Elapsed += new ElapsedEventHandler (InternalTimerElapsed); + TimerStore.Add (IdentValue, t); + return new IntPtr (IdentValue); + } + + public static void KillTimer (IntPtr timerId) + { + Timer t = (Timer) TimerStore[timerId.GetHashCode()]; + t.Stop (); + t.Elapsed -= new ElapsedEventHandler (InternalTimerElapsed); + t.Dispose (); + TimerStore.Remove (timerId.GetHashCode()); + } + + private static void InternalTimerElapsed (object e, ElapsedEventArgs args) + { + if (TimerElapsed != null) + TimerElapsed (null, new TimerElapsedEventArgs (new IntPtr(0))); + } + [MonoTODO] + public static void InvokeOnEventsThread(Delegate method) + { + throw new System.NotImplementedException (); + } + [MonoTODO] + public static event System.EventHandler DisplaySettingsChanged + { + add { throw new System.NotImplementedException ();} + remove { throw new System.NotImplementedException ();} + } + + [MonoTODO] + public static event System.EventHandler EventsThreadShutdown + { + add { throw new System.NotImplementedException ();} + remove { throw new System.NotImplementedException ();} + } + + [MonoTODO] + public static event System.EventHandler InstalledFontsChanged + { + add { throw new System.NotImplementedException ();} + remove { throw new System.NotImplementedException ();} + } + + [MonoTODO] + public static event System.EventHandler LowMemory + { + add { throw new System.NotImplementedException ();} + remove { throw new System.NotImplementedException ();} + } + + [MonoTODO] + public static event System.EventHandler PaletteChanged + { + add { throw new System.NotImplementedException ();} + remove { throw new System.NotImplementedException ();} + } + + [MonoTODO] + public static event PowerModeChangedEventHandler PowerModeChanged + { + add { throw new System.NotImplementedException ();} + remove { throw new System.NotImplementedException ();} + } + + [MonoTODO] + public static event SessionEndedEventHandler SessionEnded + { + add { throw new System.NotImplementedException ();} + remove { throw new System.NotImplementedException ();} + } + + [MonoTODO] + public static event SessionEndingEventHandler SessionEnding + { + add { throw new System.NotImplementedException ();} + remove { throw new System.NotImplementedException ();} + } + + [MonoTODO] + public static event System.EventHandler TimeChanged + { + add { throw new System.NotImplementedException ();} + remove { throw new System.NotImplementedException ();} + } + + public static event TimerElapsedEventHandler TimerElapsed; + + [MonoTODO] + public static event UserPreferenceChangedEventHandler UserPreferenceChanged + { + add { throw new System.NotImplementedException ();} + remove { throw new System.NotImplementedException ();} + } + + [MonoTODO] + public static event UserPreferenceChangingEventHandler UserPreferenceChanging + { + add { throw new System.NotImplementedException ();} + remove { throw new System.NotImplementedException ();} + } + } } -- cgit v1.2.3