本文整理汇总了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();
}
}