Answer the question
In order to leave comments, you need to log in
How to fix StackOverflowException error?
How to fix StackOverflowException error? Windows Form Application
public async static void Body()
{
await Task.Run(() =>
{
if (IsJob)
{
connectToLongPool();
while (true && IsJob)
{
try
{
scanMessages();
Thread.Sleep(100);
}
catch
{
Thread.Sleep(1000);
}
}
}
});
}
private async static void connectToLongPool()
{
try
{
HttpWebRequest pollReq = (HttpWebRequest)WebRequest.Create("https://api.vk.com/method/groups.getLongPollServer?access_token=" + Config.apiKey + "&v=5.103&group_id=" + Config.groupId);
pollReq.Method = "GET";
pollReq.Accept = "application/json";
HttpWebResponse pollResp = (HttpWebResponse)pollReq.GetResponse();
StreamReader reader = new StreamReader(pollResp.GetResponseStream());
StringBuilder builder = new StringBuilder();
string pollData = builder.Append(reader.ReadToEnd()).ToString();
JObject poolConnectJson = JObject.Parse(pollData);
ts = poolConnectJson["response"]["ts"].ToString();
key = poolConnectJson["response"]["key"].ToString();
server = poolConnectJson["response"]["server"].ToString();
Console.WriteLine(pollData);
}
catch
{
}
}
private async static void scanMessages()
{
try
{
HttpWebRequest pollReq2 = (HttpWebRequest)WebRequest.Create(server + "?act=a_check&key=" + key + "&ts=" + ts + "&mode=32&version=3");
pollReq2.Method = "GET";
pollReq2.Accept = "application/json";
HttpWebResponse pollResp2 = (HttpWebResponse)pollReq2.GetResponse(); // ошибка вылетает здесь
StreamReader reader2 = new StreamReader(pollResp2.GetResponseStream());
StringBuilder builder2 = new StringBuilder();
string pollData2 = builder2.Append(reader2.ReadToEnd()).ToString();
JObject poolConnectJson2 = JObject.Parse(pollData2);
ts = poolConnectJson2["ts"].ToString();
newEvent(poolConnectJson2);
scanMessages();
}
catch
{
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question