当前位置: 首页>>代码示例>>C#>>正文


C# Dispatcher.InvokeIfRequired方法代码示例

本文整理汇总了C#中System.Windows.Threading.Dispatcher.InvokeIfRequired方法的典型用法代码示例。如果您正苦于以下问题:C# Dispatcher.InvokeIfRequired方法的具体用法?C# Dispatcher.InvokeIfRequired怎么用?C# Dispatcher.InvokeIfRequired使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Threading.Dispatcher的用法示例。


在下文中一共展示了Dispatcher.InvokeIfRequired方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Analyze

        public async Task Analyze(Dispatcher dispatcher, IUIVisualizerService visualizer)
        {
            if (SelectedModeIds == null) throw new NullReferenceException("SelectedModeIds may not be null");
            if (SelectedSpeciesGuids == null) throw new NullReferenceException("SelectedSpeciesGuids may not be null");
            if (SelectedModeIds.Count == 0) throw new InvalidOperationException("SelectedModeIds may not be an empty list");
            if (SelectedSpeciesGuids.Count == 0) throw new InvalidOperationException("SelectedSpeciesGuids may not be an empty list");
            if (double.IsNaN(StartBinValue) || (StartBinValue < 0)) throw new InvalidOperationException("StartBinValue must be a positive value");
            if (double.IsNaN(BinWidth) || (BinWidth < 0)) throw new InvalidOperationException("BinWidth must be a positive value");
            if (BinCount <= 0) throw new InvalidOperationException("BinCount must be a positive value");
            if (FilterStartTime.Ticks < 0) throw new InvalidOperationException("FilterStartTime must be a positive value");
            if (FilterEndTime.Ticks < 0) throw new InvalidOperationException("FilterEndTime must be a positive value");
            if (FilterEndTime.Ticks <= FilterStartTime.Ticks) throw new InvalidOperationException("FilterEndTime must be greater than FilterStartTime");
            SimulationLog simulationLog = null;
            try
            {
                simulationLog = SimulationLog.Open(LogFilename);
                if (FilterEndTime.Ticks > (simulationLog.TimeStepSize.Ticks * simulationLog.TimeStepCount)) throw new InvalidOperationException("FilterEndTime cannot be greater than the last time step in the simulation");
                for (var speciesIndex = 0; speciesIndex < simulationLog.SpeciesRecords.Count; speciesIndex++) GuidToColorMap.Add(simulationLog.SpeciesRecords[speciesIndex].Guid, BarColors[speciesIndex % BarColors.Count]);

                Func<ActorExposureRecord, bool> modeFilter = record =>
                {
                    var speciesRecord = simulationLog.RecordFromActorID(record.ActorID) as SpeciesNameGuid;
                    return speciesRecord != null && SelectedModeIds.Contains(record.ModeID);
                };
                Func<ActorExposureRecord, bool> speciesFilter = record =>
                {
                    var speciesRecord = simulationLog.RecordFromActorID(record.ActorID) as SpeciesNameGuid;
                    return speciesRecord != null && SelectedSpeciesGuids.Contains(speciesRecord.Guid);
                };
                var histogramBinsViewModels = new ObservableCollection<HistogramBinsViewModel>();
                var scenarioName = simulationLog.ScenarioRecord.Name;
                var simulationStartTime = simulationLog.StartTime;
                SimulationExposuresViewModel viewModel = null;
                dispatcher.InvokeIfRequired(() =>
                {
                    viewModel = new SimulationExposuresViewModel(histogramBinsViewModels) { WindowTitle = string.Format("Scenario: {0} simulated on {1} (Processing)", scenarioName, simulationStartTime) };
                    Window = visualizer.ShowWindow("SimulationExposuresView", viewModel);
                });
                var modeThresholdHistogram = new ModeThresholdHistogram(this, simulationLog, StartBinValue, BinWidth, BinCount, modeFilter, speciesFilter);
                _modeBinsCollectionObserver = new CollectionObserver(modeThresholdHistogram.GroupedExposures.Groups)
                    .RegisterHandler((s, e) =>
                    {
                        switch (e.Action)
                        {
                            case NotifyCollectionChangedAction.Add:
                                foreach (GroupedExposuresHistogram histogram in e.NewItems) histogramBinsViewModels.Add(new HistogramBinsViewModel(histogram));
                                break;
                        }
                    });
                var timeStepIndex = 0;
                Task<bool> processTask = null;
                foreach (var timeStepRecord in simulationLog.Where(timeStepRecord => timeStepRecord.StartTime >= FilterStartTime && FilterEndTime >= timeStepRecord.StartTime))
                {
                    timeStepRecord.ReadAll();
                    timeStepIndex++;
                    var record = timeStepRecord;
                    if (processTask != null) await processTask;

                    processTask = modeThresholdHistogram.Process(record, dispatcher);

                    if (timeStepIndex % 10 == 0) UpdateHistogramDisplay();
                }
                if (processTask != null) await processTask;
                UpdateHistogramDisplay();
                viewModel.WindowTitle = string.Format("Scenario: {0} simulated on {1}", scenarioName, simulationStartTime);
                Debug.WriteLine("Finished processing simulation exposure file");
            }
            finally
            {
                if (simulationLog != null) simulationLog.Close();
            }
        }
开发者ID:AuditoryBiophysicsLab,项目名称:ESME-Workbench,代码行数:72,代码来源:SimulationLogAnalysisMainViewModel.cs


注:本文中的System.Windows.Threading.Dispatcher.InvokeIfRequired方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。