private void SaveSessionStorage() { lock (_lock) { _sessionStorage._startTime = _startTime; _sessionStorage._stopTime = _stopTime; _sessionStorage._preStartTime = _preStartTime; _sessionStorage._sessionId = _sessionId; _sessionStorage._duration = _duration; _sessionStorage._globalAttributes = CustomEvent.GetGlobalAttributes(); _sessionStorage._globalMetrics = CustomEvent.GetGlobalMetrics(); } // store session into file _logger.DebugFormat("Mobile Analytics is about to store session info: {0} ", JsonMapper.ToJson(_sessionStorage)); Action action = () => { // create a file to store session info if (!File.Exists(_sessionStorageFilePath)) { FileStream fs = File.Create(_sessionStorageFilePath); fs.Close(); File.WriteAllText(_sessionStorageFilePath, JsonMapper.ToJson(_sessionStorage)); } else { File.WriteAllText(_sessionStorageFilePath, String.Empty); File.WriteAllText(_sessionStorageFilePath, JsonMapper.ToJson(_sessionStorage)); } }; if (UnityInitializer.IsMainThread()) { action(); } else { ManualResetEvent e = new ManualResetEvent(false); UnityRequestQueue.Instance.ExecuteOnMainThread(() => { action(); e.Set(); }); e.WaitOne(); } }