Skip to content

Commit 422096b

Browse files
authored
[MWB]Fix helper process termination issue in service mode (#36892)
* [MWB] Changed to suppress the flow of the execution context * Fix build after merge * [MWB] Fix helper process termination issue in service mode * Add some comments
1 parent 318cb32 commit 422096b

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

src/modules/MouseWithoutBorders/App/Class/Common.Clipboard.cs

+8
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ private static void SendClipboardDataUsingTCP(byte[] bytes, bool image)
262262

263263
new Task(() =>
264264
{
265+
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
266+
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
267+
using var asyncFlowControl = ExecutionContext.SuppressFlow();
268+
265269
System.Threading.Thread thread = Thread.CurrentThread;
266270
thread.Name = $"{nameof(SendClipboardDataUsingTCP)}.{thread.ManagedThreadId}";
267271
Thread.UpdateThreads(thread);
@@ -386,6 +390,10 @@ internal static void GetRemoteClipboard(string postAction)
386390

387391
new Task(() =>
388392
{
393+
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
394+
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
395+
using var asyncFlowControl = ExecutionContext.SuppressFlow();
396+
389397
System.Threading.Thread thread = Thread.CurrentThread;
390398
thread.Name = $"{nameof(ConnectAndGetData)}.{thread.ManagedThreadId}";
391399
Thread.UpdateThreads(thread);

src/modules/MouseWithoutBorders/App/Class/Common.Helper.cs

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ private static void WatchDogThread()
7272

7373
private static void HelperThread()
7474
{
75+
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
76+
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
77+
using var asyncFlowControl = System.Threading.ExecutionContext.SuppressFlow();
78+
7579
try
7680
{
7781
while (true)

src/modules/MouseWithoutBorders/App/Class/Program.cs

+4
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ internal static void StartInputCallbackThread()
379379

380380
private static void InputCallbackThread()
381381
{
382+
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
383+
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
384+
using var asyncFlowControl = ExecutionContext.SuppressFlow();
385+
382386
Common.InputCallbackThreadID = Thread.CurrentThread.ManagedThreadId;
383387
while (!Common.InitDone)
384388
{

src/modules/MouseWithoutBorders/App/Class/SocketStuff.cs

+24
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,10 @@ internal int TcpSend(TcpSk tcp, DATA data)
681681

682682
private void TCPServerThread(object param)
683683
{
684+
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
685+
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
686+
using var asyncFlowControl = ExecutionContext.SuppressFlow();
687+
684688
try
685689
{
686690
TcpListener server = param as TcpListener;
@@ -768,6 +772,10 @@ private void StartNewTcpServer(TcpSk tcp, string machineName)
768772
{
769773
void ServerThread()
770774
{
775+
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
776+
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
777+
using var asyncFlowControl = ExecutionContext.SuppressFlow();
778+
771779
try
772780
{
773781
// Receiving packages
@@ -876,6 +884,10 @@ internal void StartNewTcpClient(string machineName)
876884
{
877885
void ClientThread(object obj)
878886
{
887+
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
888+
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
889+
using var asyncFlowControl = ExecutionContext.SuppressFlow();
890+
879891
IPHostEntry host;
880892
bool useName2IP = false;
881893
List<IPAddress> validAddresses = new();
@@ -1117,6 +1129,10 @@ private void StartNewTcpClientThread(string machineName, IPAddress ip)
11171129
{
11181130
void NewTcpClient()
11191131
{
1132+
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
1133+
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
1134+
using var asyncFlowControl = ExecutionContext.SuppressFlow();
1135+
11201136
TcpClient tcpClient = null;
11211137

11221138
try
@@ -1549,6 +1565,10 @@ private void MainTCPRoutine(TcpSk tcp, string machineName, bool isClient)
15491565

15501566
private static void AcceptConnectionAndSendClipboardData(object param)
15511567
{
1568+
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
1569+
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
1570+
using var asyncFlowControl = ExecutionContext.SuppressFlow();
1571+
15521572
TcpListener server = param as TcpListener;
15531573

15541574
do
@@ -1590,6 +1610,10 @@ private static void AcceptConnectionAndSendClipboardData(object param)
15901610
{
15911611
new Task(() =>
15921612
{
1613+
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
1614+
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
1615+
using var asyncFlowControl = ExecutionContext.SuppressFlow();
1616+
15931617
System.Threading.Thread thread = Thread.CurrentThread;
15941618
thread.Name = $"{nameof(SendOrReceiveClipboardData)}.{thread.ManagedThreadId}";
15951619
Thread.UpdateThreads(thread);

0 commit comments

Comments
 (0)