Fix CA 1060 by moving PInvokes to a common NativeMethodsClass

Severity Code Description Project File Line Suppression State
Warning CA1060 Move pinvokes to native methods class PowerLauncher C:\Repos\PowerToys\src\modules\launcher\PowerLauncher\App.xaml.cs 24 Active
This commit is contained in:
ryanbodrug-microsoft
2020-06-18 12:56:12 -07:00
parent b89d6d78ef
commit 165ffed9e6
11 changed files with 106 additions and 69 deletions

View File

@@ -1,3 +1,4 @@
using ManagedCommon;
using Microsoft.PowerLauncher.Telemetry;
using Microsoft.PowerToys.Telemetry;
using System;
@@ -55,7 +56,7 @@ namespace PowerLauncher
private void OnStartup(object sender, StartupEventArgs e)
{
WaitForPowerToysRunner();
RunnerHelper.WaitForPowerToysRunner(_powerToysPid);
var bootTime = new System.Diagnostics.Stopwatch();
bootTime.Start();
@@ -121,28 +122,6 @@ namespace PowerLauncher
Current.SessionEnding += (s, e) => Dispose();
}
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr OpenProcess(uint processAccess, bool bInheritHandle, int processId);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds);
private static void WaitForPowerToysRunner()
{
Task.Run(() =>
{
const uint INFINITE = 0xFFFFFFFF;
const uint WAIT_OBJECT_0 = 0x00000000;
const uint SYNCHRONIZE = 0x00100000;
IntPtr powerToysProcHandle = OpenProcess(SYNCHRONIZE, false, _powerToysPid);
if (WaitForSingleObject(powerToysProcHandle, INFINITE) == WAIT_OBJECT_0)
{
Environment.Exit(0);
}
});
}
/// <summary>
/// let exception throw as normal is better for Debug
/// </summary>

View File

@@ -84,6 +84,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
<ProjectReference Include="..\..\..\core\Microsoft.PowerToys.Settings.UI.Lib\Microsoft.PowerToys.Settings.UI.Lib.csproj" />
<ProjectReference Include="..\Wox.Core\Wox.Core.csproj" />
<ProjectReference Include="..\Wox.Infrastructure\Wox.Infrastructure.csproj" />