diff --git a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/TypingTimer.cs b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/TypingTimer.cs
index 853b73c1b..250e5b74d 100644
--- a/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/TypingTimer.cs
+++ b/dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/TypingTimer.cs
@@ -1,6 +1,7 @@
using Microsoft.Teams.AI.Utilities;
using Microsoft.Bot.Schema;
using Microsoft.Bot.Builder;
+using Microsoft.Identity.Client;
namespace Microsoft.Teams.AI
{
@@ -20,6 +21,11 @@ internal class TypingTimer : IDisposable
///
private bool _disposedValue = false;
+ ///
+ /// The send "typing" activity task
+ ///
+ private Task _lastSend = Task.CompletedTask;
+
///
/// Constructs a new instance of the class.
///
@@ -100,7 +106,8 @@ private async void SendTypingActivity(object state)
try
{
- await turnContext.SendActivityAsync(new Activity { Type = ActivityTypes.Typing });
+ _lastSend = turnContext.SendActivityAsync(new Activity { Type = ActivityTypes.Typing });
+ await _lastSend;
if (IsRunning())
{
_timer?.Change(_interval, Timeout.Infinite);
@@ -115,7 +122,7 @@ private async void SendTypingActivity(object state)
}
}
- private Task StopTimerWhenSendMessageActivityHandlerAsync(ITurnContext turnContext, List activities, Func> next)
+ private async Task StopTimerWhenSendMessageActivityHandlerAsync(ITurnContext turnContext, List activities, Func> next)
{
if (_timer != null)
{
@@ -123,13 +130,14 @@ private Task StopTimerWhenSendMessageActivityHandlerAsync(IT
{
if (activity.Type == ActivityTypes.Message)
{
+ await _lastSend;
Dispose();
break;
}
}
}
- return next();
+ return await next();
}
}
}