Amazon.UnityInitializer.IsMainThread C# (CSharp) Метод

IsMainThread() публичный статический Метод

Checks if the thread is a game/main/unity thread
public static IsMainThread ( ) : bool
Результат bool
        public static bool IsMainThread()
        {
            if (null == _mainThread)
            {
                throw new Exception("Main thread has not been set, is the AWSPrefab on the scene?");
            }
            return Thread.CurrentThread.Equals(_mainThread);
        }

Usage Example

        private static XDocument LoadConfigFromResource()
        {
            XDocument xDoc         = null;
            TextAsset awsEndpoints = null;

            Action action = () =>
            {
                awsEndpoints = Resources.Load(CONFIG_FILE) as TextAsset;

                using (Stream stream = new MemoryStream(awsEndpoints.bytes))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        xDoc = XDocument.Load(reader);
                    }
                }
            };

            if (UnityInitializer.IsMainThread())
            {
                action();
            }
            else
            {
                ManualResetEvent e = new ManualResetEvent(false);
                UnityRequestQueue.Instance.ExecuteOnMainThread(() =>
                {
                    action();
                    e.Set();
                });

                e.WaitOne();
            }
            return(xDoc);
        }
All Usage Examples Of Amazon.UnityInitializer::IsMainThread