private void Listen() { //This originally used the line transport, which is NOT BUILT for long polling. Debug.Print("[OpHandler] Listen() is getting the oprev."); //Get the byteresponse when fetching the oprevision byte[] oprev_response = connection.CallApi(URL.TalkService, Serial.Serialize("send_getLastOpRevision", new object[] { })); //Get a long value from serializing it //It looks dirty but it simply gets the byte[] array from calling a function //This honestly could be done better but at the same time, it's work. long oprev = (long)Serial.Deserialize("recv_getLastOpRevision", oprev_response); Debug.Print("[OpHandler] Beginning listener loop."); while (true) { Debug.Print("[OpHandler] Fetching operations with oprev=" + oprev); byte[] fetch_operations_response = connection.CallApi(URL.P, Serial.Serialize("send_fetchOperations", new object[] { oprev, 50 })); if (fetch_operations_response == null) { continue; // skip on 410 status code } List <Operation> fetch = (List <Operation>)Serial.Deserialize("recv_fetchOperations", fetch_operations_response); //List<Operation> fetch = service.fetchOperations(oprev, 50); Debug.Print("[OpHandler] Retrieved operation list of " + fetch.Count); for (int i = 0; i < fetch.Count; i++) { if (fetch[i].Type != OpType.END_OF_OPERATION) { oprev = fetch[i].Revision; //Register the operation recieved to the LineClient. if (_client != null) { Debug.Print("[OpHandler] Dispatching operations."); _client.RegisterOperation(fetch[i]); } else { Debug.Print("[OpHandler] Client is null, cannot dispatch operation."); } } } } }