**** Merged from MCS ****
[mono-project.git] / mcs / class / System / Microsoft.Win32 / SystemEvents.cs
blob911865874d9c4354841ba261acdeb5362fc05a38
1 //
2 // Microsoft.Win32.SystemEvents.cs
3 //
4 // Authors:
5 // Johannes Roith (johannes@jroith.de)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //
8 // (C) 2002 Johannes Roith
9 // (C) 2003 Andreas Nahr
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System;
34 using System.Timers;
35 using System.Collections;
37 namespace Microsoft.Win32
39 public sealed class SystemEvents
41 private static Hashtable TimerStore = new Hashtable ();
43 private SystemEvents ()
47 // You can use timers using the CreateTimer, KillTimer methods and the Timerelapsed event
48 // This is only a partial solution, as it only works in managed code.
49 // TODO implement this on OS level
50 // Till done this solution should work if you are only using the mentioned members
52 public static IntPtr CreateTimer (int interval)
54 Guid Ident = Guid.NewGuid ();
55 int IdentValue = Ident.GetHashCode ();
56 Timer t = new System.Timers.Timer (interval);
57 t.Elapsed += new ElapsedEventHandler (InternalTimerElapsed);
58 TimerStore.Add (IdentValue, t);
59 return new IntPtr (IdentValue);
62 public static void KillTimer (IntPtr timerId)
64 Timer t = (Timer) TimerStore[timerId.GetHashCode()];
65 t.Stop ();
66 t.Elapsed -= new ElapsedEventHandler (InternalTimerElapsed);
67 t.Dispose ();
68 TimerStore.Remove (timerId.GetHashCode());
71 private static void InternalTimerElapsed (object e, ElapsedEventArgs args)
73 if (TimerElapsed != null)
74 TimerElapsed (null, new TimerElapsedEventArgs (new IntPtr(0)));
77 [MonoTODO]
78 public static void InvokeOnEventsThread(Delegate method)
80 throw new System.NotImplementedException ();
83 [MonoTODO]
84 public static event System.EventHandler DisplaySettingsChanged
86 add { throw new System.NotImplementedException ();}
87 remove { throw new System.NotImplementedException ();}
90 [MonoTODO]
91 public static event System.EventHandler EventsThreadShutdown
93 add { throw new System.NotImplementedException ();}
94 remove { throw new System.NotImplementedException ();}
97 [MonoTODO]
98 public static event System.EventHandler InstalledFontsChanged
100 add { throw new System.NotImplementedException ();}
101 remove { throw new System.NotImplementedException ();}
104 [MonoTODO]
105 public static event System.EventHandler LowMemory
107 add { throw new System.NotImplementedException ();}
108 remove { throw new System.NotImplementedException ();}
111 [MonoTODO]
112 public static event System.EventHandler PaletteChanged
114 add { throw new System.NotImplementedException ();}
115 remove { throw new System.NotImplementedException ();}
118 [MonoTODO]
119 public static event PowerModeChangedEventHandler PowerModeChanged
121 add { throw new System.NotImplementedException ();}
122 remove { throw new System.NotImplementedException ();}
125 [MonoTODO]
126 public static event SessionEndedEventHandler SessionEnded
128 add { throw new System.NotImplementedException ();}
129 remove { throw new System.NotImplementedException ();}
132 [MonoTODO]
133 public static event SessionEndingEventHandler SessionEnding
135 add { throw new System.NotImplementedException ();}
136 remove { throw new System.NotImplementedException ();}
139 [MonoTODO]
140 public static event System.EventHandler TimeChanged
142 add { throw new System.NotImplementedException ();}
143 remove { throw new System.NotImplementedException ();}
146 public static event TimerElapsedEventHandler TimerElapsed;
148 [MonoTODO]
149 public static event UserPreferenceChangedEventHandler UserPreferenceChanged
151 add { throw new System.NotImplementedException ();}
152 remove { throw new System.NotImplementedException ();}
155 [MonoTODO]
156 public static event UserPreferenceChangingEventHandler UserPreferenceChanging
158 add { throw new System.NotImplementedException ();}
159 remove { throw new System.NotImplementedException ();}