private async Task Connect(string key, string server, string ts, Action <List <VkLongPollMessage> > onMessage = null) { var parametres = new Dictionary <string, string>(); parametres.Add("act", "a_check"); parametres.Add("key", key); parametres.Add("ts", ts); parametres.Add("wait", "25"); parametres.Add("mode", "2"); var response = await new VkRequest(new Uri("http://" + server), parametres).Execute(); VkErrorProcessor.ProcessError(response); if (response != null) { Debug.WriteLine("Long poll service response: " + response); ts = (string)response["ts"]; var result = new List <VkLongPollMessage>(); foreach (JArray update in response["updates"]) { var m = VkLongPollMessage.FromJson(update); if (m != null) { result.Add(m); } } if (onMessage != null) { onMessage(result); } if (!_stop) { await Connect(key, server, ts, onMessage); } } }
private async Task Connect(string key, string server, string ts, CancellationToken cancellationToken, Action <List <VkLongPollMessage> > onMessage = null) { var parametres = new Dictionary <string, string>(); parametres.Add("act", "a_check"); parametres.Add("key", key); parametres.Add("ts", ts); parametres.Add("wait", "25"); parametres.Add("mode", "2"); var response = await VkRequest.GetAsync("https://" + server, parametres); if (cancellationToken.IsCancellationRequested) { return; } if (response != null) { Debug.WriteLine("Long poll service response: " + response); ts = (string)response["ts"]; var result = new List <VkLongPollMessage>(); foreach (JArray update in response["updates"]) { var m = VkLongPollMessage.FromJson(update); if (m != null) { result.Add(m); } } onMessage?.Invoke(result); if (!_stop) { await Connect(key, server, ts, cancellationToken, onMessage); } } }