Reputation: 37
I'm trying to use System.Timers Timer for async Task, but I'm geting the error "Cannot access a disposed object" when I'm tring to reset my dialog in Waterfallstep.
I've tried GC.KeepAlive but did not work. I'm using bot framework SDK4 and net core 3.1.
I've tried System.Threading.Timer and the same error occured.
The proactive message does not meet my requirements to reset the whole dialog after sometime.
I will appreciate your help with this situation.
My code
{
System.Timers.Timer timer;
var dialogSet = new DialogSet(accessor);
dialogSet.Add(dialog);
var dialogContext = await dialogSet.CreateContextAsync(turnContext, cancellationToken);
var results = await dialogContext.ContinueDialogAsync(cancellationToken);
if (results.Status == DialogTurnStatus.Empty)
{
await dialogContext.BeginDialogAsync(dialog.Id, null, cancellationToken);
}
else
{
await dialogContext.ReplaceDialogAsync(dialog.Id, null, cancellationToken);
}
timer = new System.Timers.Timer(1000 * (60 * 1));
timer.Elapsed += async (sender, e) => await dialogContext.ReplaceDialogAsync(dialog.Id, null, cancellationToken);
timer.Start();
System.GC.KeepAlive(timer);
}
Upvotes: 0
Views: 134
Reputation: 1683
There are lot of documentaries on this and most of the cases are similar to the current issue. You need to setup your controller action using *PUT api/category*
Check the above link for using async Task
Upvotes: 1