Lock around downloading assets

- Added lock around downloading assets to ensure only one download task is running at a time
This commit is contained in:
tverona1
2019-08-17 17:34:53 -07:00
parent dd7b8ff6a4
commit 202d91334b
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -12,6 +12,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 20553fac56ec59645857c0732b787431, type: 3}
m_Name: OVRBuildConfig
m_EditorClassIdentifier:
androidSDKPath: C:\Users\tvero\AppData\Local\Android\Sdk
androidSDKPath:
gradlePath:
jdkPath:
+8
View File
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
@@ -30,6 +31,9 @@ namespace QuestAppLauncher
// Rate limit in minutes
const int RateLimitInMins = 5;
// Used for mutual exclusion when loading assets
static SemaphoreSlim semaphoreSlim = new SemaphoreSlim(1, 1);
/// <summary>
/// Class that tracks each file downloaded.
/// Used to determine whether an asset has been updated since last download.
@@ -75,6 +79,9 @@ namespace QuestAppLauncher
// Start background thread
Task.Run(async () =>
{
// Mutual exclusion while loading assets
await AssetsDownloader.semaphoreSlim.WaitAsync();
// Attach / detatch JNI. Required for any calls into JNI from background threads.
AndroidJNI.AttachCurrentThread();
@@ -86,6 +93,7 @@ namespace QuestAppLauncher
}
finally
{
AssetsDownloader.semaphoreSlim.Release();
AndroidJNI.DetachCurrentThread();
}
}).ContinueWith((downloadedAssets) =>