public void Run() { ProcessBinder(); if (!PopulateResourcesOnly) { foreach (var p in PendingResources) { var f = Binder.ReadFile(p.Item3); var task = new LoadResourceFromBytesTask(p.Item1, f, AccessLevel, ResourceManager.Locator.Type); task.Run(); } foreach (var t in PendingTPFs) { var f = TPF.Read(Binder.ReadFile(t.Item2)); var task = new LoadTPFResourcesTask(t.Item1, f, AccessLevel, ResourceManager.Locator.Type); task.Run(); } } PendingResources.Clear(); Binder = null; }
public Task RunAsync(IProgress <int> progress) { return(BinderTaskFactory.StartNew(() => { ProcessBinder(); if (!PopulateResourcesOnly) { bool doasync = (PendingResources.Count() + PendingTPFs.Count()) > 1; int i = 0; foreach (var p in PendingResources) { var f = Binder.ReadFile(p.Item3); var task = new LoadResourceFromBytesTask(p.Item1, f, AccessLevel, ResourceManager.Locator.Type); var size = task.GetEstimateTaskSize(); TotalSize += size; if (doasync) { var progress1 = new Progress <int>(); TaskSizes.Add(size); lock (ProgressLock) { TaskProgress.Add(0); } int bindi = i; progress1.ProgressChanged += (x, e) => { lock (ProgressLock) { TaskProgress[bindi] = e; } UpdateProgress(progress); }; LoadingTasks.Add(task.RunAsync(progress1)); i++; } else { task.Run(); i++; progress.Report(i); } } foreach (var t in PendingTPFs) { var f = TPF.Read(Binder.ReadFile(t.Item2)); var task = new LoadTPFResourcesTask(t.Item1, f, AccessLevel, ResourceManager.Locator.Type); var size = task.GetEstimateTaskSize(); TotalSize += size; if (doasync) { var progress1 = new Progress <int>(); TaskSizes.Add(size); lock (ProgressLock) { TaskProgress.Add(0); } int bindi = i; progress1.ProgressChanged += (x, e) => { lock (ProgressLock) { TaskProgress[bindi] = e; } UpdateProgress(progress); }; LoadingTasks.Add(task.RunAsync(progress1)); i++; } else { task.Run(); i++; progress.Report(i); } } } PendingResources.Clear(); // Wait for all the tasks to complete while (LoadingTasks.Count() > 0) { int idx = Task.WaitAny(LoadingTasks.ToArray()); LoadingTasks.RemoveAt(idx); } Binder = null; })); }