0

I've been dealing with this issue for a while now using HTTPClient. My async method with HTTPClient keeps throwing TaskCanceledException every few hours or so.

I've checked with IsCancellationRequested and confirmed the token was cancelled, so it's not a timeout issue.

https://i.imgur.com/QdCPcFk.png

The exception keeps being thrown on the GetAsync method below:

public async Task CheckDodgeOrStart() // checks if game started
    {
            while (true)
            {
                try
                {
                    var response = await client.GetAsync(_baseURL + /lol-gameflow/v1/gameflow-phase");

                    var stringResponse = await response.Content.ReadAsStringAsync();


                    if (stringResponse.Contains("InProgress") || stringResponse.Contains("Reconnect"))
                    {
                        if (bot.isLeader)
                        {
                            Form1.Log(_username + ": " + "Game has successfully started..");                                
                        }

                        break;
                    }

                    await Task.Delay(1000);
                }

                catch (TaskCanceledException e)
                {
                    if (!e.CancellationToken.IsCancellationRequested)
                        Console.WriteLine("Timeout");

                }
            }
    }

Help would be appreciated, thanks.

  • Could you please include the stacktrace from the exception? – Vlad Feb 15 '19 at 16:03
  • I don't have the entire stack trace I'll try and get it the next time it happens, but it said something along the lines of "throw for non-success". – Alex James Feb 15 '19 at 16:08
  • The stack trace must be a property of the exception, you can just log it along with "Timeout" string. – Vlad Feb 15 '19 at 16:09
  • Is this of any relevance? https://stackoverflow.com/a/29353046/15526 It seems like IsCancellationRequested might always be false when dealing with HttpClient – Steve Feb 15 '19 at 16:15
  • Interesting, so in this case it could be a timeout issue after all? – Alex James Feb 15 '19 at 16:35
  • After falling down a rabbit hole, I can't find the issue reported on Microsoft since connect was discontinued. But if the comment on the question is to be believed the "IsCancellationRequested always false" was fixed in .NET 4.7.2 Which framework version are you using? – David Feb 15 '19 at 17:16
  • I'm using 4.5.2 – Alex James Feb 15 '19 at 17:33

0 Answers0