Skip to content

Commit

Permalink
测试windows系统事件类SystemEvents,该类需要用户交互的消息循环,在后台运行时拿不到消息,也就没有事件触发
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Mar 18, 2024
1 parent d198a86 commit 7397d2e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
53 changes: 52 additions & 1 deletion Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.Win32;
using NewLife;
using NewLife.IO;
using NewLife.Log;
Expand All @@ -27,7 +28,7 @@ static void Main(String[] args)
{
XTrace.UseConsole();

Test6();
Test7();

Console.WriteLine("OK!");
Console.ReadKey();
Expand Down Expand Up @@ -193,6 +194,56 @@ static void Test6()
}
}

static void Test7()
{
XTrace.WriteLine("SystemEvents");

SystemEvents.PowerModeChanged += (s, e) =>
{
XTrace.WriteLine("PowerModeChanged: {0}", e.Mode);
};
SystemEvents.SessionSwitch += (s, e) =>
{
XTrace.WriteLine("SessionSwitch: {0}", e.Reason);
};
SystemEvents.SessionEnding += (s, e) =>
{
XTrace.WriteLine("SessionEnding: {0}", e.Reason);
};
SystemEvents.SessionEnded += (s, e) =>
{
XTrace.WriteLine("SessionEnded: {0}", e.Reason);
};
SystemEvents.UserPreferenceChanging += (s, e) =>
{
XTrace.WriteLine("UserPreferenceChanging: {0}", e.Category);
};
SystemEvents.UserPreferenceChanged += (s, e) =>
{
XTrace.WriteLine("UserPreferenceChanged: {0}", e.Category);
};
SystemEvents.DisplaySettingsChanged += (s, e) =>
{
XTrace.WriteLine("DisplaySettingsChanged: {0}", e);
};
SystemEvents.InstalledFontsChanged += (s, e) =>
{
XTrace.WriteLine("InstalledFontsChanged: {0}", e);
};
SystemEvents.TimeChanged += (s, e) =>
{
XTrace.WriteLine("TimeChanged: {0}", e);
};
SystemEvents.TimerElapsed += (s, e) =>
{
XTrace.WriteLine("TimerElapsed: {0}", e);
};
SystemEvents.LowMemory += (s, e) =>
{
XTrace.WriteLine("LowMemory: {0}", e);
};
}

static void Test8()
{
var str = "runtime=6.0;version>=1.0";
Expand Down
1 change: 1 addition & 0 deletions Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Win32.SystemEvents" Version="8.0.0" />
<PackageReference Include="NewLife.Core" Version="10.8.2024.303" />
<PackageReference Include="SSH.NET" Version="2024.0.0" />
</ItemGroup>
Expand Down

0 comments on commit 7397d2e

Please sign in to comment.