private HelpshiftWorker() { callerQueue = new Queue <APICallInfo> (); // Worker thread to read and execute from queue. workerThread = new Thread(() => { try { // Attach current thread to android JNI. AndroidJNI.AttachCurrentThread(); while (!shouldStop) { // Execute from queue. while (!shouldStop && callerQueue.Count > 0) { APICallInfo apiInfo = callerQueue.Dequeue(); try { resolveHsApiCall(apiInfo); } catch (Exception e) { // Catch all exceptions since we want the thread to be running. Debug.Log("Error in : " + apiInfo.apiName + ". Exception : " + e.Message + e.StackTrace); } } if (!shouldStop) { waitHandle.WaitOne(); waitHandle.Reset(); } } } finally { AndroidJNI.DetachCurrentThread(); } }); workerThread.Name = "HSAsyncThread"; workerThread.Start(); }
public void resolveHsApiCall(APICallInfo apiInfo) { if (apiInfo.resetEvent != null) { apiInfo.resetEvent.Set(); return; } listeners [apiInfo.instanceIdentifier].resolveAndCallApi(apiInfo.methodIdentifier, apiInfo.apiName, apiInfo.args); }