private void run(object state)
{
//try
{
SynchronizationContext context = state as SynchronizationContext;
context.Send(this.doGetLongPollServerConnectionData, null);
context.Send(this.doGetSendRequest, null);
while (!this.stopPending)
{
this.lastLongPollMessage = ApiRequest.Send("http://" + this.Server + "?act=a_check&key=" + this.Key + "&ts=" + this.LastEventId.ToString() + "&wait=" + this.WaitTime.ToString());
if (this.lastLongPollMessage == "")
{
continue;
}
// {"ts":727820493,"updates":[[8,-696076,0]]}
if (new Regex("\\\"?failed\\\"?\\s*?\\:\\s*?\\d+").Match(this.lastLongPollMessage).Success)
{
Console.WriteLine(this.lastLongPollMessage);
context.Send(this.doGetLongPollServerConnectionData, null);
}
else
{
this.LastEventId = Convert.ToInt32(new Regex("\\{[\\s]*?\\\"ts\\\"[\\s]*?\\:[\\s]*?(\\d+)[\\s]*?").Match(this.lastLongPollMessage).Groups[1].Value);
if (this.lastLongPollMessage != "" && this.lastLongPollMessage != null)
{
if (!new Regex("\\\"updates\\\"\\:\\[\\]").Match(this.lastLongPollMessage).Success)
{
this.longPollMessages.Add(this.lastLongPollMessage);
LongPollServerEventArgs args = new LongPollServerEventArgs();
args.LastEventId = this.LastEventId;
args.EventSourceCode = this.lastLongPollMessage;
context.Post(this.doOnDataReceived, args);
}
}
}
}
}
//catch
//{ }
//finally
{
}
}