コード例 #1
0
        public override void InitializeAsync()
        {
            _asyncWorker = new BackgroundWorker {
                WorkerSupportsCancellation = true
            };
            _asyncWorker.DoWork += delegate
            {
                if (!_isLoadingAsync && (MaterialAssets == null || MaterialAssets.Count == 0))
                {
                    _isLoadingAsync = true;

                    IsBusy = true;
                    var filename = SourceVoxelFilepath ?? VoxelFilepath;

                    Dictionary <string, long> details;
                    try
                    {
                        details = MyVoxelMap.GetMaterialAssetDetails(filename);
                    }
                    catch
                    {
                        IsBusy          = false;
                        _isLoadingAsync = false;
                        return;
                    }
                    var sum  = details.Values.ToList().Sum();
                    var list = new List <VoxelMaterialAssetModel>();

                    foreach (var kvp in details)
                    {
                        list.Add(new VoxelMaterialAssetModel {
                            MaterialName = kvp.Key, Volume = (double)kvp.Value / 255, Percent = (double)kvp.Value / (double)sum
                        });
                    }

                    MaterialAssets = list;
                    IsBusy         = false;

                    _isLoadingAsync = false;
                }
            };

            _asyncWorker.RunWorkerAsync();
        }