Answer the question
In order to leave comments, you need to log in
How to reconnect on webclient error?
this is how I do reconnect now, but what if it fails to connect and download data twice, is there a solution?
Stream data;
StreamReader reader;
try
{
data = client.OpenRead("https://api.vk.com/method/groups.getById?" + window.Token + "&group_ids=" + groups_ids + "&v=" + window.version);
reader = new StreamReader(data);
}
catch (Exception)
{
data = client.OpenRead("https://api.vk.com/method/groups.getById?" + window.Token + "&group_ids=" + groups_ids + "&v=" + window.version);
reader = new StreamReader(data);
}
Answer the question
In order to leave comments, you need to log in
the easiest:
Stream data;
StreamReader reader;
while(true) // тут в условие можете поставить счетчик попыток реконнекта и соответственно оформить его в теле цикла
{
try
{
data = client.OpenRead("https://api.vk.com/method/groups.getById?" + window.Token + "&group_ids=" + groups_ids + "&v=" + window.version);
reader = new StreamReader(data);
break;
}
catch (Exception)
{
// тут можно писать ошибки в лог
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question