void ProcessRequests()
{
// Make a network call for queued requests on the main thread
var request = UnityRequestQueue.Instance.DequeueRequest();
if (request != null)
{
StartCoroutine(InvokeRequest(request));
}
// Invoke queued callbacks on the main thread
var asyncResult = UnityRequestQueue.Instance.DequeueCallback();
if (asyncResult != null && asyncResult.Action != null)
{
try
{
asyncResult.Action(asyncResult.Request, asyncResult.Response,
asyncResult.Exception, asyncResult.AsyncOptions);
}
catch (Exception exception)
{
// Catch any unhandled exceptions from the user callback
// and log it.
_logger.Error(exception,
"An unhandled exception was thrown from the callback method {0}.",
asyncResult.Request.ToString());
}
}
//Invoke queued main thread executions
var mainThreadCallback = UnityRequestQueue.Instance.DequeueMainThreadOperation();
if (mainThreadCallback != null)
{
try
{
mainThreadCallback();
}
catch (Exception exception)
{
// Catch any unhandled exceptions from the user callback
// and log it.
_logger.Error(exception,
"An unhandled exception was thrown from the callback method");
}
}
//trigger network updates if status has changed
var nr = ServiceFactory.Instance.GetService<INetworkReachability>() as Amazon.Util.Internal.PlatformServices.NetworkReachability;
if (_currentNetworkStatus != nr.NetworkStatus)
{
_currentNetworkStatus = nr.NetworkStatus;
nr.OnNetworkReachabilityChanged(_currentNetworkStatus);
}
}