void onInvoke(int id) { // Check the state of the request running with this id. var wrappedRequest = runningRequests.FirstOrDefault(x => x.ID == id); if (wrappedRequest != null && wrappedRequest.Request.isDone) { if (wrappedRequest.Request.isNetworkError || !string.IsNullOrEmpty(wrappedRequest.Request.error)) { // Invoke Failed event in case of any error with the request. if (Failed != null) { Failed(wrappedRequest, wrappedRequest.Request.error); } } else { // Invoke Completed event once the request is done. if (Completed != null) { Completed(wrappedRequest); } } // Stop the TaskInvoker task once the request is done. TaskInvoker.StopTask(id); runningRequests.Remove(wrappedRequest); } }
void OnApplicationPause(bool paused) { // Start the counter on pause if (paused) { // Start a task that invokes once every second (1000 milliseconds) currentTaskID = TaskInvoker.StartTask(1000, onInvoke, onExpire); } else if (currentTaskID != -1) { // Stop the running task when entering foreground TaskInvoker.StopTask(currentTaskID); } }