Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
 public void resolveHsApiCall(APICallInfo apiInfo)
 {
     if (apiInfo.resetEvent != null)
     {
         apiInfo.resetEvent.Set();
         return;
     }
     listeners [apiInfo.instanceIdentifier].resolveAndCallApi(apiInfo.methodIdentifier,
                                                              apiInfo.apiName, apiInfo.args);
 }