@@ -242,14 +242,15 @@ public void RdpEx(TimelineHandler handler, TimelineEvent timelineEvent, string c
242
242
process . StandardInput . Close ( ) ; // line added to stop process from hanging on ReadToEnd()
243
243
Thread . Sleep ( 2000 ) ; //give time for response
244
244
checkPasswordPrompt ( au , password , username , usePasswordOnly ) ;
245
- //wait 3 minutes for connection window
246
- if ( ! findRdpWindow ( target , 3 ) )
245
+ //wait 15 seconds for connection window
246
+ if ( ! findRdpWindow ( target , 15 ) )
247
247
{
248
248
//may have a certificate problem
249
+ Log . Trace ( "RDP:: Unable to find a RDP window, attempting to accept an untrusted certificate" ) ;
249
250
checkGenericPrompt ( au , "{TAB}{TAB}{TAB}{ENTER}" ) ; //this is for a certificate prompt
250
251
}
251
- //try again for another 3 minutes to find
252
- if ( findRdpWindow ( target , 3 ) )
252
+ //try again for another 4.25 minutes to find
253
+ if ( findRdpWindow ( target , 255 ) )
253
254
{
254
255
doMouseLoop ( caption , target , au , timelineEvent ) ;
255
256
}
@@ -278,18 +279,18 @@ public void RdpEx(TimelineHandler handler, TimelineEvent timelineEvent, string c
278
279
}
279
280
}
280
281
281
- public bool findRdpWindow ( string target , int minutes )
282
+ public bool findRdpWindow ( string target , int timeout )
282
283
{
283
284
var caption = $ "{ target } - Remote Desktop Connection";
284
285
var winHandle = Winuser . FindWindow ( "TscShellContainerClass" , caption ) ;
285
- int count = 0 ;
286
+ int wait = 1 ; //time to wait for this loop (exponential back off: 2^n starting with n=0)
286
287
//wait for window to appear
287
288
while ( winHandle == IntPtr . Zero )
288
289
{
289
- Log . Trace ( $ "RDP:: Unable to find desktop window for { target } , sleeping 1 minute ") ;
290
- Thread . Sleep ( 60 * 1000 ) ; //sleep 1 minute, then try again
291
- count ++ ;
292
- if ( count >= minutes ) break ;
290
+ Log . Trace ( $ "RDP:: Unable to find desktop window for { target } , sleeping { wait } seconds ") ;
291
+ Thread . Sleep ( wait * 1000 ) ; //sleep for exponential back off amount of seconds
292
+ if ( 2 * wait - 1 >= timeout ) break ; // sum(2^n) from n=0 -> n=x is 2 * 2^x - 1
293
+ wait = 2 * wait ; //double the time to wait next loop (2^n)
293
294
winHandle = Winuser . FindWindow ( "TscShellContainerClass" , caption ) ;
294
295
}
295
296
return winHandle != IntPtr . Zero ;
0 commit comments