I'm developing a .net core application using RestSharp.RestClient (105.2.4-rc4-24214-01). I set
RestClient.Timeout=1
or
RestClient.Timeout=10000
and then call my test API
var tcs = new TaskCompletionSource<IRestResponse>();
RestClient.ExecuteAsync(request, response => { tcs.SetResult(response); })
return tcs.Task.Result;
But it still use default value 100000 and generate "A task was canceled." exception only after 100000 ms.
How can i change this value?
The default value of the REST client response timeout is 120 seconds.
RestSharp does not use connection pool as HttpClient and does not leave opened sockets after the use. That's why it is safe (and recommended) to create a new instance of RestClient per request.
RestSharp supports both synchronous and asynchronous requests. This article presents a discussion of how we can work with RestSharp to consume services built using ASP.NET Core.
RestSharp is a C# library used to build and send API requests, and interpret the responses. It is used as part of the C#Bot API testing framework to build the requests, send them to the server, and interpret the responses so assertions can be made.
The documentation says the Request.Timeout overrides the RestClient.Timeout. Try this:
var tcs = new TaskCompletionSource<IRestResponse>();
request.Timeout = 10000;
RestClient.ExecuteAsync(request, response => { tcs.SetResult(response); })
return tcs.Task.Result;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With