Skip to content

Commit

Permalink
[MWB]Fix helper process termination issue in service mode (#36892)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
YDKK authored Jan 22, 2025
1 parent 318cb32 commit 422096b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/modules/MouseWithoutBorders/App/Class/Common.Clipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ private static void SendClipboardDataUsingTCP(byte[] bytes, bool image)

new Task(() =>
{
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
using var asyncFlowControl = ExecutionContext.SuppressFlow();

System.Threading.Thread thread = Thread.CurrentThread;
thread.Name = $"{nameof(SendClipboardDataUsingTCP)}.{thread.ManagedThreadId}";
Thread.UpdateThreads(thread);
Expand Down Expand Up @@ -386,6 +390,10 @@ internal static void GetRemoteClipboard(string postAction)

new Task(() =>
{
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
using var asyncFlowControl = ExecutionContext.SuppressFlow();

System.Threading.Thread thread = Thread.CurrentThread;
thread.Name = $"{nameof(ConnectAndGetData)}.{thread.ManagedThreadId}";
Thread.UpdateThreads(thread);
Expand Down
4 changes: 4 additions & 0 deletions src/modules/MouseWithoutBorders/App/Class/Common.Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ private static void WatchDogThread()

private static void HelperThread()
{
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
using var asyncFlowControl = System.Threading.ExecutionContext.SuppressFlow();

try
{
while (true)
Expand Down
4 changes: 4 additions & 0 deletions src/modules/MouseWithoutBorders/App/Class/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ internal static void StartInputCallbackThread()

private static void InputCallbackThread()
{
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
using var asyncFlowControl = ExecutionContext.SuppressFlow();

Common.InputCallbackThreadID = Thread.CurrentThread.ManagedThreadId;
while (!Common.InitDone)
{
Expand Down
24 changes: 24 additions & 0 deletions src/modules/MouseWithoutBorders/App/Class/SocketStuff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,10 @@ internal int TcpSend(TcpSk tcp, DATA data)

private void TCPServerThread(object param)
{
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
using var asyncFlowControl = ExecutionContext.SuppressFlow();

try
{
TcpListener server = param as TcpListener;
Expand Down Expand Up @@ -768,6 +772,10 @@ private void StartNewTcpServer(TcpSk tcp, string machineName)
{
void ServerThread()
{
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
using var asyncFlowControl = ExecutionContext.SuppressFlow();

try
{
// Receiving packages
Expand Down Expand Up @@ -876,6 +884,10 @@ internal void StartNewTcpClient(string machineName)
{
void ClientThread(object obj)
{
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
using var asyncFlowControl = ExecutionContext.SuppressFlow();

IPHostEntry host;
bool useName2IP = false;
List<IPAddress> validAddresses = new();
Expand Down Expand Up @@ -1117,6 +1129,10 @@ private void StartNewTcpClientThread(string machineName, IPAddress ip)
{
void NewTcpClient()
{
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
using var asyncFlowControl = ExecutionContext.SuppressFlow();

TcpClient tcpClient = null;

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

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

TcpListener server = param as TcpListener;

do
Expand Down Expand Up @@ -1590,6 +1610,10 @@ private static void AcceptConnectionAndSendClipboardData(object param)
{
new Task(() =>
{
// SuppressFlow fixes an issue on service mode, where the helper process can't get enough permissions to be started again.
// More details can be found on: https://github.com/microsoft/PowerToys/pull/36892
using var asyncFlowControl = ExecutionContext.SuppressFlow();

System.Threading.Thread thread = Thread.CurrentThread;
thread.Name = $"{nameof(SendOrReceiveClipboardData)}.{thread.ManagedThreadId}";
Thread.UpdateThreads(thread);
Expand Down

0 comments on commit 422096b

Please sign in to comment.