TaskCanceledException
Hi,
I get sometimes this TaskCanceledException:
System.Threading.Tasks.TaskCanceledException: A task was canceled. at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable'1.ConfiguredTaskAwaiter.GetResult() at Telegram.Bot.Api.<SendWebRequest>d__89'1.MoveNext() in D:\Bitbucket\Bot\Telegram.Bot\Api.cs:line 1060 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter'1.GetResult() at Telegram.Bot.Service.Core.<SendMessageHtml>d__17.MoveNext() in D:\Bitbucket\Bot\Telegram.Bot.Service\Core.cs:line 291
It comes from this line, in Api.SendWebRequestresponse = await client.PostAsync(uri, form).ConfigureAwait(false);
Do you know the reason?
I have the same problem! It occurs when I'm sending video files with moderate size, event with 5MB in size. Maybe slow connection causes this exception!
The default timeout is 1 min. Have you tried increasing it? It's TelegramBotClient.UploadTimeout in the current 10.x beta and Api.UploadTimeout before.
I've increased the UploadTimeout, I'll see if the exception occurs again. But my bot is on a server with a gigabit connection... Is there anything else which can generate this exception?
made this better to understand by warping the exception in an ApiRequestException
Looks like this happens because httpClient.Timout is set to "timeout" parameter + 1 second. If request is not completed in timeout + 1 seconds, it will throw an error. And as I understand this can happen easily if there are some lags in connection.
Have the same problem, when use subscribing on event Api.UpdateReceived. Sometimes this exception randomly throws from Api and crashs my app. Is there the way for me to handle this exception anyway becides the AppDomain.CurrentDomain.UnhandledException =)
what version do you use?
<package id="Telegram.Bot" version="9.0.0" targetFramework="net45" />
@KozhevnikovDmitry I think you can handle these exceptions by putting a try catch around the StartReceiving
StartReceiving isn't throwing exceptions. the exceptions which occur during Receiving will be emit the OnReceiveError event
That's what I need.
Seems to me that the issue can be closed if it is fixed now...?