-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowsDisplaySwitchService.cs
More file actions
51 lines (43 loc) · 1.25 KB
/
Copy pathWindowsDisplaySwitchService.cs
File metadata and controls
51 lines (43 loc) · 1.25 KB
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
using System;
using System.Diagnostics;
using System.Threading.Tasks;
namespace DisplayDeck;
public static class WindowsDisplaySwitchService
{
public static Task ExtendDesktopAsync(int settleDelayMs)
{
return RunDisplaySwitchAsync("/extend", settleDelayMs);
}
public static Task ExternalOnlyAsync(int settleDelayMs)
{
return RunDisplaySwitchAsync("/external", settleDelayMs);
}
private static async Task RunDisplaySwitchAsync(string arguments, int settleDelayMs)
{
try
{
using Process process = new Process();
process.StartInfo = new ProcessStartInfo
{
FileName = "displayswitch.exe",
Arguments = arguments,
UseShellExecute = true,
CreateNoWindow = true
};
process.Start();
try
{
await process.WaitForExitAsync();
}
catch
{
// Windows may hand this off to the shell.
}
}
catch
{
// Continue with normal display switching logic if DisplaySwitch cannot be launched.
}
await Task.Delay(Math.Max(settleDelayMs, 3500));
}
}