@@ -120,14 +120,6 @@ public override async Task<DialogTurnResult> ContinueDialogAsync(DialogContext d
120120                return  await  PromptUserAsync ( dc ,  cancellationToken ) . ConfigureAwait ( false ) ; 
121121            } 
122122
123-             //Handle case where we timed out 
124-             var  activity  =  dc . Context . Activity ; 
125-             if  ( ! wasInterrupted  &&  activity . Type  !=  ActivityTypes . Message  &&  activity . Name  ==  ActivityEventNames . ContinueConversation ) 
126-             { 
127-                 await  SendActivityAsync ( dc ,  cancellationToken ) . ConfigureAwait ( false ) ; 
128-                 return  await  dc . EndDialogAsync ( cancellationToken :  cancellationToken ) . ConfigureAwait ( false ) ; 
129-             } 
130- 
131123            //Get value of termination string from expression 
132124            string  regexPattern  =  this . TerminationConditionRegexPattern ? . GetValue ( dc . State ) ; 
133125
@@ -198,6 +190,19 @@ protected override async Task<bool> OnPreBubbleEventAsync(DialogContext dc, Dial
198190            return  false ; 
199191        } 
200192
193+         protected  async  Task  CheckForTimeoutAsync ( DialogContext  dc ,  CancellationToken  cancellationToken ) 
194+         { 
195+             //Handle case where we timed out 
196+             var  interrupted  =  dc . State . GetValue < bool > ( TurnPath . Interrupted ,  ( )  =>  false ) ; 
197+             var  activity  =  dc . Context . Activity ; 
198+             if  ( ! interrupted  &&  activity . Type  !=  ActivityTypes . Message  &&  activity . Name  ==  ActivityEventNames . ContinueConversation ) 
199+             { 
200+                 //Send the default message to the user and end the dialog 
201+                 await  SendActivityAsync ( dc ,  cancellationToken ) . ConfigureAwait ( false ) ; 
202+                 await  dc . EndDialogAsync ( cancellationToken :  cancellationToken ) . ConfigureAwait ( false ) ; 
203+             } 
204+         } 
205+ 
201206        private  async  Task < DialogTurnResult >  PromptUserAsync ( DialogContext  dc ,  CancellationToken  cancellationToken  =  default ( CancellationToken ) ) 
202207        { 
203208            //Do we already have a value stored? This would happen in the interruption case, a case in which we are looping over ourselves, or maybe we had a fatal error and had to restart the dialog tree 
@@ -256,15 +261,11 @@ protected override async Task<bool> OnPreBubbleEventAsync(DialogContext dc, Dial
256261            return  new  DialogTurnResult ( DialogTurnStatus . Complete ) ; 
257262        } 
258263
259-         private  void  CreateTimerForConversation ( DialogContext  dc ,  string  timerId ,  CancellationToken  cancellationToken ) 
264+         private  void  CreateTimerForConversation ( DialogContext  dc ,  int   timeout ,   string  timerId ,  CancellationToken  cancellationToken ) 
260265        { 
261266            BotAdapter  adapter  =  dc . Context . Adapter ; 
262-             var  identity  =  dc . Context . TurnState . Get < ClaimsIdentity > ( "BotIdentity" ) ; 
263- 
264267            ConversationReference  conversationReference  =  dc . Context . Activity . GetConversationReference ( ) ; 
265-             var  timeoutExpression  =  this . TimeOutInMilliseconds  ??  throw  new  InvalidOperationException ( $ "Value for TimeOutInMilliseconds property is not defined.") ; 
266-             int  timeout  =  timeoutExpression . GetValue ( dc . State ) ; 
267- 
268+             var  identity  =  dc . Context . TurnState . Get < ClaimsIdentity > ( "BotIdentity" ) ; 
268269            var  audience  =  dc . Context . TurnState . Get < string > ( BotAdapter . OAuthScopeKey ) ; 
269270
270271            //Question remaining to be answered: Will this task get garbage collected? If so, we need to maintain a handle for it. 
@@ -287,10 +288,15 @@ await adapter.ContinueConversationAsync(
287288
288289        private  async  Task  InitTimeoutTimerAsync ( DialogContext  dc ,  CancellationToken  cancellationToken ) 
289290        { 
290-             var  timerId  =  Guid . NewGuid ( ) . ToString ( ) ; 
291-             CreateTimerForConversation ( dc ,  timerId ,  cancellationToken ) ; 
292-             await  stateMatrix . StartAsync ( timerId ) . ConfigureAwait ( false ) ; 
293-             dc . State . SetValue ( "this.TimerId" ,  timerId ) ; 
291+             var  timeout  =  this . TimeOutInMilliseconds ? . GetValue ( dc . State )  ??  0 ; 
292+ 
293+             if  ( timeout  >  0 ) 
294+             { 
295+                 var  timerId  =  Guid . NewGuid ( ) . ToString ( ) ; 
296+                 CreateTimerForConversation ( dc ,  timeout ,  timerId ,  cancellationToken ) ; 
297+                 await  stateMatrix . StartAsync ( timerId ) . ConfigureAwait ( false ) ; 
298+                 dc . State . SetValue ( "this.TimerId" ,  timerId ) ; 
299+             } 
294300        } 
295301    } 
296302} 
0 commit comments