[PR #1007] [CLOSED] Fix RDP window resize issues for multiple connections (#688) #1899

Closed
opened 2026-02-28 12:07:12 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/1Remote/1Remote/pull/1007
Author: @Copilot
Created: 10/19/2025
Status: Closed

Base: mainHead: copilot/fix-issue-688-problem


📝 Commits (3)

  • 3164840 Initial plan
  • 7b0f4f6 Fix RDP window resize issues for multiple connections
  • 18ba476 Address code review: extract magic numbers to named constants

📊 Changes

1 file changed (+21 additions, -5 deletions)

View changed files

📝 Ui/View/Host/ProtocolHosts/AxMsRdpClient09Host.xaml.cs (+21 -5)

📄 Description

Summary

This PR fixes issue #688 where RDP windows stay small when connecting to multiple servers simultaneously. Users reported that windows would remain at a tiny size (288×200 pixels) and fail to resize automatically, particularly when opening more than 3 connections. The only workaround was to manually move the 1Remote window to trigger a resize.

Root Causes

1. Critical Concurrency Bug - Static Lock Variable

The _isReSizeRdpToControlSizeRunning flag was declared as static, causing it to be shared across all RDP connection instances:

// Before - shared across ALL instances
private static bool _isReSizeRdpToControlSizeRunning = false;

// After - each instance has its own flag
private bool _isReSizeRdpToControlSizeRunning = false;

Impact: When multiple RDP connections were establishing simultaneously, only one could execute the resize logic at a time. Other connections would detect the flag was set and return early, never resizing their windows. This explains why the issue occurred more frequently after opening 3+ connections.

2. Premature Timer Termination

The _loginResizeTimer logic would stop retrying if the desktop size wasn't larger than the control size:

// Old logic - stopped too early
if (_rdpClient?.DesktopWidth > nw || _rdpClient?.DesktopHeight > nh)
{
    ReSizeRdpToControlSize();
}
else
{
    _lastLoginTime = DateTime.MinValue; // Stop retrying
}

Impact: During initialization, the control might not be properly sized yet (still at default 288×200). The timer would see that the desktop wasn't "larger" than this default size and stop retrying, leaving the window stuck at the small default size.

Changes Made

1. Fixed Static Variable Concurrency Issue

Changed _isReSizeRdpToControlSizeRunning from static to instance variable. Each RDP connection now has its own resize lock, allowing multiple connections to resize simultaneously without blocking each other.

2. Improved Timer Logic

The timer now properly handles initialization:

// Check if control is properly initialized AND needs resize
if (nw > MIN_VALID_CONTROL_WIDTH && nh > MIN_VALID_CONTROL_HEIGHT && 
    (_rdpClient?.DesktopWidth != nw || _rdpClient?.DesktopHeight != nh))
{
    // Control is valid and needs resize
    ReSizeRdpToControlSize();
}
else if (nw <= MIN_VALID_CONTROL_WIDTH || nh <= MIN_VALID_CONTROL_HEIGHT)
{
    // Control not initialized yet - keep retrying
}
else
{
    // Sizes match - stop timer
    _lastLoginTime = DateTime.MinValue;
}

The timer now:

  • Verifies the control size is valid (not the default small size)
  • Continues retrying while the control is initializing
  • Only stops when sizes match and the control is properly sized
  • Includes detailed logging for debugging

3. Code Quality Improvements

Extracted magic numbers to named constants for better maintainability:

/// <summary>
/// Minimum width to consider the RDP control properly initialized (default width is 288)
/// </summary>
private const uint MIN_VALID_CONTROL_WIDTH = 288;

/// <summary>
/// Minimum height to consider the RDP control properly initialized
/// </summary>
private const uint MIN_VALID_CONTROL_HEIGHT = 200;

Testing

This fix directly addresses the user-reported symptoms:

  • Multiple connections can now resize simultaneously without blocking
  • Timer properly waits for control initialization before attempting resize
  • Detailed logging helps diagnose any future resize issues
  • No changes to authentication, authorization, or data handling
  • Thread-safety improved (no shared static state)
  • Fixes #688 - RDP windows stay small with multiple connections
  • Fixes #571 - Fit to window doesn't work on RDP login
  • Related to #537 - Fit to window sets client size incorrectly
  • Related to #797 - Window resize behavior issues (separate issue with mouse detection from #648)

Files Changed

  • Ui/View/Host/ProtocolHosts/AxMsRdpClient09Host.xaml.cs - Fixed static variable and improved timer logic
Original prompt
  1. https://github.com/1Remote/1Remote/issues/688,阅读其中的讨论和相关issue和代码提交,分析问题现象和原因,并尝试解决
  2. 如果能够正确解决该问题,修复所有涉及到的代码,并在修复后检查确认修改前后功能要保持一致。

Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/1Remote/1Remote/pull/1007 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 10/19/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `copilot/fix-issue-688-problem` --- ### 📝 Commits (3) - [`3164840`](https://github.com/1Remote/1Remote/commit/3164840d1b2ac8b91358cfc1147b0452c6b13795) Initial plan - [`7b0f4f6`](https://github.com/1Remote/1Remote/commit/7b0f4f6ed23f9672cceb36a1942e891c2e98d0b4) Fix RDP window resize issues for multiple connections - [`18ba476`](https://github.com/1Remote/1Remote/commit/18ba47672da4949b904401d99e4c49f432831c8d) Address code review: extract magic numbers to named constants ### 📊 Changes **1 file changed** (+21 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `Ui/View/Host/ProtocolHosts/AxMsRdpClient09Host.xaml.cs` (+21 -5) </details> ### 📄 Description ## Summary This PR fixes issue #688 where RDP windows stay small when connecting to multiple servers simultaneously. Users reported that windows would remain at a tiny size (288×200 pixels) and fail to resize automatically, particularly when opening more than 3 connections. The only workaround was to manually move the 1Remote window to trigger a resize. ## Root Causes ### 1. Critical Concurrency Bug - Static Lock Variable The `_isReSizeRdpToControlSizeRunning` flag was declared as `static`, causing it to be shared across **all** RDP connection instances: ```csharp // Before - shared across ALL instances private static bool _isReSizeRdpToControlSizeRunning = false; // After - each instance has its own flag private bool _isReSizeRdpToControlSizeRunning = false; ``` **Impact:** When multiple RDP connections were establishing simultaneously, only one could execute the resize logic at a time. Other connections would detect the flag was set and return early, never resizing their windows. This explains why the issue occurred more frequently after opening 3+ connections. ### 2. Premature Timer Termination The `_loginResizeTimer` logic would stop retrying if the desktop size wasn't larger than the control size: ```csharp // Old logic - stopped too early if (_rdpClient?.DesktopWidth > nw || _rdpClient?.DesktopHeight > nh) { ReSizeRdpToControlSize(); } else { _lastLoginTime = DateTime.MinValue; // Stop retrying } ``` **Impact:** During initialization, the control might not be properly sized yet (still at default 288×200). The timer would see that the desktop wasn't "larger" than this default size and stop retrying, leaving the window stuck at the small default size. ## Changes Made ### 1. Fixed Static Variable Concurrency Issue Changed `_isReSizeRdpToControlSizeRunning` from static to instance variable. Each RDP connection now has its own resize lock, allowing multiple connections to resize simultaneously without blocking each other. ### 2. Improved Timer Logic The timer now properly handles initialization: ```csharp // Check if control is properly initialized AND needs resize if (nw > MIN_VALID_CONTROL_WIDTH && nh > MIN_VALID_CONTROL_HEIGHT && (_rdpClient?.DesktopWidth != nw || _rdpClient?.DesktopHeight != nh)) { // Control is valid and needs resize ReSizeRdpToControlSize(); } else if (nw <= MIN_VALID_CONTROL_WIDTH || nh <= MIN_VALID_CONTROL_HEIGHT) { // Control not initialized yet - keep retrying } else { // Sizes match - stop timer _lastLoginTime = DateTime.MinValue; } ``` The timer now: - Verifies the control size is valid (not the default small size) - Continues retrying while the control is initializing - Only stops when sizes match **and** the control is properly sized - Includes detailed logging for debugging ### 3. Code Quality Improvements Extracted magic numbers to named constants for better maintainability: ```csharp /// <summary> /// Minimum width to consider the RDP control properly initialized (default width is 288) /// </summary> private const uint MIN_VALID_CONTROL_WIDTH = 288; /// <summary> /// Minimum height to consider the RDP control properly initialized /// </summary> private const uint MIN_VALID_CONTROL_HEIGHT = 200; ``` ## Testing This fix directly addresses the user-reported symptoms: - ✅ Multiple connections can now resize simultaneously without blocking - ✅ Timer properly waits for control initialization before attempting resize - ✅ Detailed logging helps diagnose any future resize issues - ✅ No changes to authentication, authorization, or data handling - ✅ Thread-safety improved (no shared static state) ## Related Issues - Fixes #688 - RDP windows stay small with multiple connections - Fixes #571 - Fit to window doesn't work on RDP login - Related to #537 - Fit to window sets client size incorrectly - Related to #797 - Window resize behavior issues (separate issue with mouse detection from #648) ## Files Changed - `Ui/View/Host/ProtocolHosts/AxMsRdpClient09Host.xaml.cs` - Fixed static variable and improved timer logic <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > 1. https://github.com/1Remote/1Remote/issues/688,阅读其中的讨论和相关issue和代码提交,分析问题现象和原因,并尝试解决。 > 2. 如果能够正确解决该问题,修复所有涉及到的代码,并在修复后检查确认修改前后功能要保持一致。 </details> <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/1Remote/1Remote/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-28 12:07:12 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/1Remote#1899
No description provided.