forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSystemEvents.xml
766 lines (665 loc) · 41.7 KB
/
SystemEvents.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
<Type Name="SystemEvents" FullName="Microsoft.Win32.SystemEvents">
<TypeSignature Language="C#" Value="public sealed class SystemEvents" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi sealed beforefieldinit SystemEvents extends System.Object" />
<TypeSignature Language="DocId" Value="T:Microsoft.Win32.SystemEvents" />
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>Provides access to system event notifications. This class cannot be inherited.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:Microsoft.Win32.SystemEvents> class provides the ability to respond to specific types of system events.
When a system event is raised, any delegates attached to the event are called using the thread that monitors for system events. Therefore, you should make any calls from your event handlers thread-safe. If you need to call a system event that is not exposed as a member of this class, you can use the <xref:Microsoft.Win32.SystemEvents.InvokeOnEventsThread%2A> method.
> [!CAUTION]
> Do not perform time-consuming processing on the thread that raises a system event handler because it might prevent other applications from functioning.
> [!NOTE]
> Some system events might not be raised on [!INCLUDE[windowsver](~/includes/windowsver-md.md)]. Be sure to verify that your application works as expected on [!INCLUDE[windowsver](~/includes/windowsver-md.md)].
## Examples
This section contains two examples. The first example shows how to use system events in an ordinary application, and the second example shows how to use system events in a Windows service.
**Example 1**
The following code example registers interest in some system events and then waits for any of those events to occur. The output shown occurs if the user changes the display resolution.
[!code-cpp[SystemEvents#1](~/samples/snippets/cpp/VS_Snippets_Winforms/SystemEvents/cpp/SystemEvents.cpp#1)]
[!code-csharp[SystemEvents#1](~/samples/snippets/csharp/VS_Snippets_Winforms/SystemEvents/CS/SystemEvents.cs#1)]
[!code-vb[SystemEvents#1](~/samples/snippets/visualbasic/VS_Snippets_Winforms/SystemEvents/VB/SystemEvents.vb#1)]
**Example 2**
The following code example demonstrates a very simple Windows service that handles the <xref:Microsoft.Win32.SystemEvents.TimeChanged> and <xref:Microsoft.Win32.SystemEvents.UserPreferenceChanged> events. The example includes a service named `SimpleService`, a form named `HiddenForm`, and an installer. The form provides the message loop that is required by system events.
> [!NOTE]
> Services do not have message loops, unless they are allowed to interact with the desktop. If the message loop is not provided by a hidden form, as in this example, the service must be run under the local system account, and manual intervention is required to enable interaction with the desktop. That is, the administrator must manually check the **Allow service to interact with desktop** check box on the **Log On** tab of the service properties dialog box. In that case, a message loop is automatically provided. This option is available only when the service is run under the local system account. Interaction with the desktop cannot be enabled programmatically.
The service in this example starts a thread that runs an instance of `HiddenForm`. The events are hooked up and handled in the form. The events must be hooked up in the load event of the form, to make sure that the form is completely loaded first; otherwise the events will not be raised.
> [!NOTE]
> The example provides all the necessary code, including the form initialization code typically generated by [!INCLUDE[vsprvs](~/includes/vsprvs-md.md)] designers. If you are developing your service in [!INCLUDE[vsprvs](~/includes/vsprvs-md.md)], you can omit the second partial class and use the **Properties** window to set the height and width of the hidden form to zero, the border style to <xref:System.Windows.Forms.FormBorderStyle?displayProperty=fullName>, and the window state to <xref:System.Windows.Forms.FormWindowState?displayProperty=fullName>.
To run the example:
1. Compile the code from the command line. The name that you use for the source file is not important.
2. Install the service from the command line using the [Installutil.exe (Installer Tool)](~/docs/framework/tools/installutil-exe-installer-tool.md) utility. For example, `InstallUtil example.exe` if the source file name is `example.cs` or `example.vb`. You must be an administrator to install the service.
3. Use the Services console to start the service.
4. Change the system time, or change user preferences, such as mouse properties.
5. View the messages in the **Application** category of Event Viewer.
6. Use the Services console to stop the service.
7. Uninstall the service from the command line by using the `/u` option. For example, `InstallUtil /u example.exe`.
[!code-csharp[ManagedWindowsService#1](~/samples/snippets/csharp/VS_Snippets_CLR/ManagedWindowsService/cs/source.cs#1)]
[!code-vb[ManagedWindowsService#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/ManagedWindowsService/VB/source.vb#1)]
]]></format>
</remarks>
<permission cref="T:System.Security.NamedPermissionSet">for full access to system resources. Demand values: <see cref="F:System.Security.Permissions.SecurityAction.LinkDemand" />. Associated state:</permission>
</Docs>
<Members>
<Member MemberName="CreateTimer">
<MemberSignature Language="C#" Value="public static IntPtr CreateTimer (int interval);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig native int CreateTimer(int32 interval) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.Win32.SystemEvents.CreateTimer(System.Int32)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.IntPtr</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="interval" Type="System.Int32" />
</Parameters>
<Docs>
<param name="interval">Specifies the interval between timer notifications, in milliseconds.</param>
<summary>Creates a new window timer associated with the system events window.</summary>
<returns>The ID of the new timer.</returns>
<remarks>To be added.</remarks>
<exception cref="T:System.ArgumentException">The interval is less than or equal to zero.</exception>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed, or the attempt to create the timer did not succeed.</exception>
</Docs>
</Member>
<Member MemberName="DisplaySettingsChanged">
<MemberSignature Language="C#" Value="public static event EventHandler DisplaySettingsChanged;" />
<MemberSignature Language="ILAsm" Value=".event class System.EventHandler DisplaySettingsChanged" />
<MemberSignature Language="DocId" Value="E:Microsoft.Win32.SystemEvents.DisplaySettingsChanged" />
<MemberType>Event</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.MonoTODO</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.EventHandler</ReturnType>
</ReturnValue>
<Docs>
<summary>Occurs when the user changes the display settings.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
> [!CAUTION]
> Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
## Examples
The following code example demonstrates how to monitor the <xref:Microsoft.Win32.SystemEvents.DisplaySettingsChanged> event. This code example is part of a larger example provided for the <xref:Microsoft.Win32.SystemEvents> class.
[!code-cpp[SystemEvents#2](~/samples/snippets/cpp/VS_Snippets_Winforms/SystemEvents/cpp/SystemEvents.cpp#2)]
[!code-csharp[SystemEvents#2](~/samples/snippets/csharp/VS_Snippets_Winforms/SystemEvents/CS/SystemEvents.cs#2)]
[!code-vb[SystemEvents#2](~/samples/snippets/visualbasic/VS_Snippets_Winforms/SystemEvents/VB/SystemEvents.vb#2)]
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed.</exception>
</Docs>
</Member>
<Member MemberName="DisplaySettingsChanging">
<MemberSignature Language="C#" Value="public static event EventHandler DisplaySettingsChanging;" />
<MemberSignature Language="ILAsm" Value=".event class System.EventHandler DisplaySettingsChanging" />
<MemberSignature Language="DocId" Value="E:Microsoft.Win32.SystemEvents.DisplaySettingsChanging" />
<MemberType>Event</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.MonoTODO("Currently does nothing on Mono")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.EventHandler</ReturnType>
</ReturnValue>
<Docs>
<summary>Occurs when the display settings are changing.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
> [!CAUTION]
> Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed.</exception>
</Docs>
</Member>
<Member MemberName="EventsThreadShutdown">
<MemberSignature Language="C#" Value="public static event EventHandler EventsThreadShutdown;" />
<MemberSignature Language="ILAsm" Value=".event class System.EventHandler EventsThreadShutdown" />
<MemberSignature Language="DocId" Value="E:Microsoft.Win32.SystemEvents.EventsThreadShutdown" />
<MemberType>Event</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.MonoTODO("Currently does nothing on Mono")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.EventHandler</ReturnType>
</ReturnValue>
<Docs>
<summary>Occurs before the thread that listens for system events is terminated.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This event is raised as the thread that listens for system events is about to be terminated. System event delegates are invoked using the thread that listens for system events.
> [!CAUTION]
> Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed.</exception>
</Docs>
</Member>
<Member MemberName="InstalledFontsChanged">
<MemberSignature Language="C#" Value="public static event EventHandler InstalledFontsChanged;" />
<MemberSignature Language="ILAsm" Value=".event class System.EventHandler InstalledFontsChanged" />
<MemberSignature Language="DocId" Value="E:Microsoft.Win32.SystemEvents.InstalledFontsChanged" />
<MemberType>Event</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.MonoTODO("Currently does nothing on Mono")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.EventHandler</ReturnType>
</ReturnValue>
<Docs>
<summary>Occurs when the user adds fonts to or removes fonts from the system.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
> [!CAUTION]
> Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed.</exception>
</Docs>
</Member>
<Member MemberName="InvokeOnEventsThread">
<MemberSignature Language="C#" Value="public static void InvokeOnEventsThread (Delegate method);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void InvokeOnEventsThread(class System.Delegate method) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.Win32.SystemEvents.InvokeOnEventsThread(System.Delegate)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.MonoTODO</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="method" Type="System.Delegate" />
</Parameters>
<Docs>
<param name="method">A delegate to invoke using the thread that listens for system events.</param>
<summary>Invokes the specified delegate using the thread that listens for system events.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
You can use this method any time that you need to handle a system event that is not exposed otherwise by the <xref:Microsoft.Win32.SystemEvents> class.
When you call this method, the specified delegate will be invoked by the thread that your application is using to process system events.
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed.</exception>
</Docs>
</Member>
<Member MemberName="KillTimer">
<MemberSignature Language="C#" Value="public static void KillTimer (IntPtr timerId);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig void KillTimer(native int timerId) cil managed" />
<MemberSignature Language="DocId" Value="M:Microsoft.Win32.SystemEvents.KillTimer(System.IntPtr)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="timerId" Type="System.IntPtr" />
</Parameters>
<Docs>
<param name="timerId">The ID of the timer to terminate.</param>
<summary>Terminates the timer specified by the given id.</summary>
<remarks>To be added.</remarks>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed, or the attempt to terminate the timer did not succeed.</exception>
</Docs>
</Member>
<Member MemberName="LowMemory">
<MemberSignature Language="C#" Value="public static event EventHandler LowMemory;" />
<MemberSignature Language="ILAsm" Value=".event class System.EventHandler LowMemory" />
<MemberSignature Language="DocId" Value="E:Microsoft.Win32.SystemEvents.LowMemory" />
<MemberType>Event</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.ComponentModel.Browsable(false)</AttributeName>
</Attribute>
<Attribute>
<AttributeName>System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)</AttributeName>
</Attribute>
<Attribute>
<AttributeName>System.MonoTODO("Currently does nothing on Mono")</AttributeName>
</Attribute>
<Attribute>
<AttributeName>System.Obsolete("")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.EventHandler</ReturnType>
</ReturnValue>
<Docs>
<summary>Occurs when the system is running out of available RAM.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This event wraps the WM_COMPACTING message. This message is sent to all top-level windows when the system detects more than 12.5 percent of system time over a 30- to 60-second interval is being spent compacting memory. This indicates that system memory is low.
> [!NOTE]
> This event is only raised if the message pump is running. In a Windows service, unless a hidden form is used or the message pump has been started manually, this event will not be raised. For a code example that shows how to handle system events by using a hidden form in a Windows service, see the <xref:Microsoft.Win32.SystemEvents> class.
> [!CAUTION]
> Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed.</exception>
<block subset="none" type="usage">
<para>This message is provided only for compatibility with 16-bit Windows-based applications.</para>
</block>
</Docs>
</Member>
<Member MemberName="PaletteChanged">
<MemberSignature Language="C#" Value="public static event EventHandler PaletteChanged;" />
<MemberSignature Language="ILAsm" Value=".event class System.EventHandler PaletteChanged" />
<MemberSignature Language="DocId" Value="E:Microsoft.Win32.SystemEvents.PaletteChanged" />
<MemberType>Event</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.MonoTODO("Currently does nothing on Mono")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.EventHandler</ReturnType>
</ReturnValue>
<Docs>
<summary>Occurs when the user switches to an application that uses a different palette.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
> [!NOTE]
> This event is only raised if the message pump is running. In a Windows service, unless a hidden form is used or the message pump has been started manually, this event will not be raised. For a code example that shows how to handle system events by using a hidden form in a Windows service, see the <xref:Microsoft.Win32.SystemEvents> class.
> [!CAUTION]
> Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
## Examples
The following code example demonstrates how to monitor the <xref:Microsoft.Win32.SystemEvents.PaletteChanged> event. This code example is part of a larger example provided for the <xref:Microsoft.Win32.SystemEvents> class.
[!code-cpp[SystemEvents#2](~/samples/snippets/cpp/VS_Snippets_Winforms/SystemEvents/cpp/SystemEvents.cpp#2)]
[!code-csharp[SystemEvents#2](~/samples/snippets/csharp/VS_Snippets_Winforms/SystemEvents/CS/SystemEvents.cs#2)]
[!code-vb[SystemEvents#2](~/samples/snippets/visualbasic/VS_Snippets_Winforms/SystemEvents/VB/SystemEvents.vb#2)]
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed.</exception>
</Docs>
</Member>
<Member MemberName="PowerModeChanged">
<MemberSignature Language="C#" Value="public static event Microsoft.Win32.PowerModeChangedEventHandler PowerModeChanged;" />
<MemberSignature Language="ILAsm" Value=".event class Microsoft.Win32.PowerModeChangedEventHandler PowerModeChanged" />
<MemberSignature Language="DocId" Value="E:Microsoft.Win32.SystemEvents.PowerModeChanged" />
<MemberType>Event</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.MonoTODO("Currently does nothing on Mono")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>Microsoft.Win32.PowerModeChangedEventHandler</ReturnType>
</ReturnValue>
<Docs>
<summary>Occurs when the user suspends or resumes the system.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
> [!NOTE]
> This event is only raised if the message pump is running. In a Windows service, unless a hidden form is used or the message pump has been started manually, this event will not be raised. For a code example that shows how to handle system events by using a hidden form in a Windows service, see the <xref:Microsoft.Win32.SystemEvents> class.
> [!CAUTION]
> Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed.</exception>
</Docs>
</Member>
<Member MemberName="SessionEnded">
<MemberSignature Language="C#" Value="public static event Microsoft.Win32.SessionEndedEventHandler SessionEnded;" />
<MemberSignature Language="ILAsm" Value=".event class Microsoft.Win32.SessionEndedEventHandler SessionEnded" />
<MemberSignature Language="DocId" Value="E:Microsoft.Win32.SystemEvents.SessionEnded" />
<MemberType>Event</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.MonoTODO("Currently does nothing on Mono")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>Microsoft.Win32.SessionEndedEventHandler</ReturnType>
</ReturnValue>
<Docs>
<summary>Occurs when the user is logging off or shutting down the system.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
> [!NOTE]
> This event is only raised if the message pump is running. In a Windows service, unless a hidden form is used or the message pump has been started manually, this event will not be raised. For a code example that shows how to handle system events by using a hidden form in a Windows service, see the <xref:Microsoft.Win32.SystemEvents> class.
> [!CAUTION]
> Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed.</exception>
</Docs>
</Member>
<Member MemberName="SessionEnding">
<MemberSignature Language="C#" Value="public static event Microsoft.Win32.SessionEndingEventHandler SessionEnding;" />
<MemberSignature Language="ILAsm" Value=".event class Microsoft.Win32.SessionEndingEventHandler SessionEnding" />
<MemberSignature Language="DocId" Value="E:Microsoft.Win32.SystemEvents.SessionEnding" />
<MemberType>Event</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.MonoTODO("Currently does nothing on Mono")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>Microsoft.Win32.SessionEndingEventHandler</ReturnType>
</ReturnValue>
<Docs>
<summary>Occurs when the user is trying to log off or shut down the system.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This is a cancelable event. Setting the <xref:Microsoft.Win32.SessionEndingEventArgs.Cancel%2A> property to `true` will request that the session continues to run. It provides no guarantee that the session will not end.
If you are using <xref:Microsoft.Win32.SystemEvents.SessionEnding> in a Windows form to detect a system logoff or reboot, there is no deterministic way to decide whether the <xref:System.Windows.Forms.Form.Closing> event will fire before this event.
If you want to perform some special tasks before <xref:System.Windows.Forms.Form.Closing> is fired, you need to ensure that <xref:Microsoft.Win32.SystemEvents.SessionEnding> fires before <xref:System.Windows.Forms.Form.Closing>. To do this, you need to trap the `WM_QUERYENDSESSION` in the form by overriding the `WndProc` function. This example demonstrates how to do this.
```vb
Private Shared WM_QUERYENDSESSION As Integer = &H11
Private Shared systemShutdown As Boolean = False
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_QUERYENDSESSION Then
MessageBox.Show("queryendsession: this is a logoff, shutdown, or reboot")
systemShutdown = True
End If
' If this is WM_QUERYENDSESSION, the closing event should be raised in the base WndProc.
MyBase.WndProc(m)
End Sub 'WndProc
Private Sub Form1_Closing(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If (systemShutdown) Then
' Reset the variable because the user might cancel the shutdown.
systemShutdown = False
If (System.Windows.Forms.DialogResult.Yes = _
MessageBox.Show("My application", "Do you want to save your work before logging off?", MessageBoxButtons.YesNo)) Then
e.Cancel = True
Else
e.Cancel = False
End If
End If
End Sub
```
```csharp
private static int WM_QUERYENDSESSION = 0x11;
private static bool systemShutdown = false;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m.Msg==WM_QUERYENDSESSION)
{
MessageBox.Show("queryendsession: this is a logoff, shutdown, or reboot");
systemShutdown = true;
}
// If this is WM_QUERYENDSESSION, the closing event should be
// raised in the base WndProc.
base.WndProc(ref m);
} //WndProc
private void Form1_Closing(
System.Object sender,
System.ComponentModel.CancelEventArgs e)
{
if (systemShutdown)
// Reset the variable because the user might cancel the
// shutdown.
{
systemShutdown = false;
if (DialogResult.Yes==MessageBox.Show("My application",
"Do you want to save your work before logging off?",
MessageBoxButtons.YesNo))
{
e.Cancel = true;
}
else
{
e.Cancel = false;
}
}
}
```
> [!IMPORTANT]
> Console applications do not raise the <xref:Microsoft.Win32.SystemEvents.SessionEnding> event.
> [!NOTE]
> This event is only raised if the message pump is running. In a Windows service, unless a hidden form is used or the message pump has been started manually, this event will not be raised. For a code example that shows how to handle system events by using a hidden form in a Windows service, see the <xref:Microsoft.Win32.SystemEvents> class.
> [!CAUTION]
> Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed.</exception>
</Docs>
</Member>
<Member MemberName="SessionSwitch">
<MemberSignature Language="C#" Value="public static event Microsoft.Win32.SessionSwitchEventHandler SessionSwitch;" />
<MemberSignature Language="ILAsm" Value=".event class Microsoft.Win32.SessionSwitchEventHandler SessionSwitch" />
<MemberSignature Language="DocId" Value="E:Microsoft.Win32.SystemEvents.SessionSwitch" />
<MemberType>Event</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.MonoTODO("Currently does nothing on Mono")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>Microsoft.Win32.SessionSwitchEventHandler</ReturnType>
</ReturnValue>
<Docs>
<summary>Occurs when the currently logged-in user has changed.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
> [!NOTE]
> This event is only raised if the message pump is running. In a Windows service, unless a hidden form is used or the message pump has been started manually, this event will not be raised. For a code example that shows how to handle system events by using a hidden form in a Windows service, see the <xref:Microsoft.Win32.SystemEvents> class.
> [!CAUTION]
> Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed.</exception>
</Docs>
</Member>
<Member MemberName="TimeChanged">
<MemberSignature Language="C#" Value="public static event EventHandler TimeChanged;" />
<MemberSignature Language="ILAsm" Value=".event class System.EventHandler TimeChanged" />
<MemberSignature Language="DocId" Value="E:Microsoft.Win32.SystemEvents.TimeChanged" />
<MemberType>Event</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.MonoTODO("Currently does nothing on Mono")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.EventHandler</ReturnType>
</ReturnValue>
<Docs>
<summary>Occurs when the user changes the time on the system clock.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
> [!NOTE]
> This event is only raised if the message pump is running. In a Windows service, unless a hidden form is used or the message pump has been started manually, this event will not be raised. For a code example that shows how to handle system events by using a hidden form in a Windows service, see the <xref:Microsoft.Win32.SystemEvents> class.
> [!CAUTION]
> Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed.</exception>
</Docs>
</Member>
<Member MemberName="TimerElapsed">
<MemberSignature Language="C#" Value="public static event Microsoft.Win32.TimerElapsedEventHandler TimerElapsed;" />
<MemberSignature Language="ILAsm" Value=".event class Microsoft.Win32.TimerElapsedEventHandler TimerElapsed" />
<MemberSignature Language="DocId" Value="E:Microsoft.Win32.SystemEvents.TimerElapsed" />
<MemberType>Event</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>Microsoft.Win32.TimerElapsedEventHandler</ReturnType>
</ReturnValue>
<Docs>
<summary>Occurs when a windows timer interval has expired.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
> [!NOTE]
> This event is only raised if the message pump is running. In a Windows service, unless a hidden form is used or the message pump has been started manually, this event will not be raised. For a code example that shows how to handle system events by using a hidden form in a Windows service, see the <xref:Microsoft.Win32.SystemEvents> class.
> [!CAUTION]
> Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed.</exception>
</Docs>
</Member>
<Member MemberName="UserPreferenceChanged">
<MemberSignature Language="C#" Value="public static event Microsoft.Win32.UserPreferenceChangedEventHandler UserPreferenceChanged;" />
<MemberSignature Language="ILAsm" Value=".event class Microsoft.Win32.UserPreferenceChangedEventHandler UserPreferenceChanged" />
<MemberSignature Language="DocId" Value="E:Microsoft.Win32.SystemEvents.UserPreferenceChanged" />
<MemberType>Event</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.MonoTODO("Currently does nothing on Mono")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>Microsoft.Win32.UserPreferenceChangedEventHandler</ReturnType>
</ReturnValue>
<Docs>
<summary>Occurs when a user preference has changed.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
> [!NOTE]
> This event is only raised if the message pump is running. In a Windows service, unless a hidden form is used or the message pump has been started manually, this event will not be raised. For a code example that shows how to handle system events by using a hidden form in a Windows service, see the <xref:Microsoft.Win32.SystemEvents> class.
> [!CAUTION]
> Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed.</exception>
</Docs>
</Member>
<Member MemberName="UserPreferenceChanging">
<MemberSignature Language="C#" Value="public static event Microsoft.Win32.UserPreferenceChangingEventHandler UserPreferenceChanging;" />
<MemberSignature Language="ILAsm" Value=".event class Microsoft.Win32.UserPreferenceChangingEventHandler UserPreferenceChanging" />
<MemberSignature Language="DocId" Value="E:Microsoft.Win32.SystemEvents.UserPreferenceChanging" />
<MemberType>Event</MemberType>
<AssemblyInfo>
<AssemblyName>System</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.MonoTODO("Currently does nothing on Mono")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>Microsoft.Win32.UserPreferenceChangingEventHandler</ReturnType>
</ReturnValue>
<Docs>
<summary>Occurs when a user preference is changing.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
> [!NOTE]
> This event is only raised if the message pump is running. In a Windows service, unless a hidden form is used or the message pump has been started manually, this event will not be raised. For a code example that shows how to handle system events by using a hidden form in a Windows service, see the <xref:Microsoft.Win32.SystemEvents> class.
> [!CAUTION]
> Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.
## Examples
The following code example demonstrates how to monitor the <xref:Microsoft.Win32.SystemEvents.UserPreferenceChanging> event. This code example is part of a larger example provided for the <xref:Microsoft.Win32.SystemEvents> class.
[!code-cpp[SystemEvents#2](~/samples/snippets/cpp/VS_Snippets_Winforms/SystemEvents/cpp/SystemEvents.cpp#2)]
[!code-csharp[SystemEvents#2](~/samples/snippets/csharp/VS_Snippets_Winforms/SystemEvents/CS/SystemEvents.cs#2)]
[!code-vb[SystemEvents#2](~/samples/snippets/visualbasic/VS_Snippets_Winforms/SystemEvents/VB/SystemEvents.vb#2)]
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">System event notifications are not supported under the current context. Server processes, for example, might not support global system event notifications.</exception>
<exception cref="T:System.Runtime.InteropServices.ExternalException">The attempt to create a system events window thread did not succeed.</exception>
</Docs>
</Member>
</Members>
</Type>