Rafael Venancio Dev
Rafael Venancio Dev

Reputation: 37

Microsoft BotFramework v4 replace Dialog problem with Timers

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.

https://learn.microsoft.com/en-us/azure/bot-service/bot-builder-howto-proactive-message?view=azure-bot-service-4.0&tabs=csharp

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

Answers (1)

Sairam Tadepalli
Sairam Tadepalli

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*

https://entityframeworkcore.com/knowledge-base/57952486/using-async-repository-pattern---cannot-access-a-disposed-object

Check the above link for using async Task

Upvotes: 1

Related Questions