@@ -37,8 +37,6 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
3737 private Process _process ;
3838 private IntPtr _appWin ;
3939
40- private readonly DispatcherTimer _resizeTimer = new DispatcherTimer ( ) ;
41-
4240 private bool _isConnected ;
4341 public bool IsConnected
4442 {
@@ -78,9 +76,6 @@ public TigerVNCControl(TigerVNCSessionInfo info)
7876
7977 _sessionInfo = info ;
8078
81- _resizeTimer . Tick += ResizeTimer_Tick ;
82- _resizeTimer . Interval = new TimeSpan ( 0 , 0 , 0 , 0 , 500 ) ;
83-
8479 Dispatcher . ShutdownStarted += Dispatcher_ShutdownStarted ;
8580 }
8681
@@ -145,18 +140,6 @@ private async Task Connect()
145140
146141 while ( ( DateTime . Now - startTime ) . TotalSeconds < 10 )
147142 {
148- // Fix for netcore3.1 https://stackoverflow.com/questions/60342879/process-mainwindowhandle-is-non-zero-in-net-framework-but-zero-in-net-core-unl
149- /*
150- try
151- {
152- _process = Process.GetProcessById(_process.Id);
153- }
154- catch
155- {
156- break; // Process has exited
157- }
158- */
159-
160143 _process . Refresh ( ) ;
161144
162145 if ( _process . HasExited )
@@ -167,15 +150,15 @@ private async Task Connect()
167150 if ( IntPtr . Zero != _appWin )
168151 break ;
169152
170- await Task . Delay ( 50 ) ;
153+ await Task . Delay ( 100 ) ;
171154 }
172155 }
173156
174157 if ( _appWin != IntPtr . Zero )
175158 {
176159 while ( ! _process . HasExited && _process . MainWindowTitle . IndexOf ( " - TigerVNC" , StringComparison . Ordinal ) == - 1 )
177160 {
178- await Task . Delay ( 50 ) ;
161+ await Task . Delay ( 100 ) ;
179162
180163 _process . Refresh ( ) ;
181164 }
@@ -197,7 +180,9 @@ private async Task Connect()
197180
198181 IsConnected = true ;
199182
200- // Resize embedded application & refresh
183+ // Resize embedded application & refresh
184+ // Requires a short delay because it's not applied immediately
185+ await Task . Delay ( 250 ) ;
201186 ResizeEmbeddedWindow ( ) ;
202187 }
203188 }
@@ -212,10 +197,10 @@ private async Task Connect()
212197 if ( ! _closing )
213198 {
214199 var settings = AppearanceManager . MetroDialog ;
215- settings . AffirmativeButtonText = NETworkManager . Localization . Resources . Strings . OK ;
200+ settings . AffirmativeButtonText = Localization . Resources . Strings . OK ;
216201 ConfigurationManager . Current . FixAirspace = true ;
217202
218- await _dialogCoordinator . ShowMessageAsync ( this , NETworkManager . Localization . Resources . Strings . Error ,
203+ await _dialogCoordinator . ShowMessageAsync ( this , Localization . Resources . Strings . Error ,
219204 ex . Message , MessageDialogStyle . Affirmative , settings ) ;
220205
221206 ConfigurationManager . Current . FixAirspace = false ;
@@ -239,7 +224,7 @@ private void ResizeEmbeddedWindow()
239224
240225 public void Disconnect ( )
241226 {
242- if ( _process != null && ! _process . HasExited )
227+ if ( IsConnected )
243228 _process . Kill ( ) ;
244229 }
245230
@@ -262,16 +247,9 @@ public void CloseTab()
262247 #region Events
263248 private void TigerVNCGrid_SizeChanged ( object sender , SizeChangedEventArgs e )
264249 {
265- if ( _process != null )
250+ if ( IsConnected )
266251 ResizeEmbeddedWindow ( ) ;
267252 }
268-
269- private void ResizeTimer_Tick ( object sender , EventArgs e )
270- {
271- _resizeTimer . Stop ( ) ;
272-
273- ResizeEmbeddedWindow ( ) ;
274- }
275253 #endregion
276254 }
277255}
0 commit comments