static void WaitUntilComplete(System.Threading.Tasks.ParallelLoopResult result) { while (!result.IsCompleted) { System.Threading.Thread.Sleep(500); } }
public void ReadDataFilesAsync(ContentStorage loc, GameDirectory gameDir, string searchPattern, Action <KSoft.IO.XmlElementStream, FA> streamProc, out System.Threading.Tasks.ParallelLoopResult result) { Contract.Requires(!string.IsNullOrEmpty(searchPattern)); result = System.Threading.Tasks.Parallel.ForEach(Directories.GetFiles(loc, gameDir, searchPattern), (filename) => { const FA k_mode = FA.Read; using (var s = new KSoft.IO.XmlElementStream(filename, k_mode, this)) { SetupStream(s); streamProc(s, k_mode); } }); }
public void LoadFromFile() { string filePath = UnityEditor.EditorUtility.OpenFilePanel("LogFile", Application.temporaryCachePath, "log"); if (!System.IO.File.Exists(filePath)) { return; } string[] logItemsJson = System.IO.File.ReadAllLines(filePath); LogItem[] logItems = new LogItem[logItemsJson.Length]; bool[] successs = new bool[logItems.Length]; System.Threading.Tasks.ParallelLoopResult parallelLoopResult = System.Threading.Tasks.Parallel.For(0, logItems.Length, iItem => { string iterJson = logItemsJson[iItem]; if (string.IsNullOrEmpty(iterJson)) { successs[iItem] = false; } else { try { logItems[iItem] = new LogItem(LitJson.JsonMapper.ToObject <LogItem>(logItemsJson[iItem])); successs[iItem] = true; } catch (Exception) { successs[iItem] = false; } } }); while (!parallelLoopResult.IsCompleted) { } for (int iLog = 0; iLog < logItems.Length; iLog++) { if (successs[iLog]) { _OnLogReceived(logItems[iLog]); } } }