-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
area-System.Net.HttpquestionAnswer questions and provide assistance, not an issue with source code or documentation.Answer questions and provide assistance, not an issue with source code or documentation.
Milestone
Description
Hi there. I am getting an HTTP stream and reading it until it sends some data but I need to figure out how to set a timeout in case of not receiving data from the stream which I'm reading using StreamReader class. This stream sends me data every 50-80 seconds and I wanna handle it when it does not send any data in this timestamp.The sample code is below:
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri(_configuration.GetSection("COnfig").GetValue<string>("Url"));
var streamresponse = await client.GetStreamAsync("stream");
using (StreamReader reader = new StreamReader(streamresponse))
{
//reader.BaseStream.ReadTimeout = 2000;
while (true)
{
string line = await reader.ReadLineAsync();
if (!string.IsNullOrWhiteSpace(line))
{
string decoded = HttpUtility.UrlDecode(line, Encoding.GetEncoding("UTF-8")); ;
//some logic
}
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-System.Net.HttpquestionAnswer questions and provide assistance, not an issue with source code or documentation.Answer questions and provide assistance, not an issue with source code or documentation.