public void ImportModels(float progress0, float progress100) { ProgressBar(progress0, "Exporting Models..."); List <AssetRef> modelAssets = AssetsByType[AssetRef.Types.DME]; int assetsProcessed = 0; string lastAssetProcessed = ""; Parallel.AsyncForEach <AssetRef> parallelTask = System.Threading.Tasks.Parallel.ForEach; IAsyncResult result = parallelTask.BeginInvoke(modelAssets, asset => { Interlocked.Increment(ref assetsProcessed); if (asset == null) { return; } //Don't export if the file already exists. if (File.Exists(ResourceDirectory + "/Models/" + Path.GetFileNameWithoutExtension(asset.Name) + ".obj")) { return; } //Names string assetName = asset.Name; string assetDisplayName = BuildAssetName(assetName, asset.Pack.Name); //De-serialize using (MemoryStream modelMemoryStream = asset.Pack.CreateAssetMemoryStreamByName(assetName)) { Model model = Model.LoadFromStream(assetName, assetDisplayName, modelMemoryStream); if (model == null) { return; } ModelExporter.ExportModel(this, model, ResourceDirectory + "/Models"); lastAssetProcessed = assetName; } }, null, null); while (!result.IsCompleted) { ProgressBar(MathUtils.Remap01(assetsProcessed / (float)modelAssets.Count, progress0, progress100), "Exporting Model: " + lastAssetProcessed); } parallelTask.EndInvoke(result); }