控制台刷新优化
This commit is contained in:
parent
96bdd42528
commit
07b536895a
@ -180,7 +180,10 @@ public partial class App : Application
|
||||
services.AddTransient<HomeViewModel>();
|
||||
services.AddTransient<ProjectInfoViewModel>();
|
||||
services.AddTransient<TestHostViewModel>();
|
||||
services.AddTransient<ExperimentConsoleViewModel>();
|
||||
// The experiment console controls application-wide hardware and is not
|
||||
// owned by a project. Keep one instance so switching project pages does
|
||||
// not replace its state or interrupt its refresh loop.
|
||||
services.AddSingleton<ExperimentConsoleViewModel>();
|
||||
services.AddTransient<BasicTestViewModel>();
|
||||
services.AddTransient<CurveTestViewModel>();
|
||||
services.AddTransient<PowerTestViewModel>();
|
||||
|
||||
@ -17,6 +17,7 @@ public partial class ExperimentConsoleViewModel : ObservableObject
|
||||
private readonly UserSettingsStore _settingsStore;
|
||||
private readonly UiLogSink _log;
|
||||
private readonly object _pollLock = new();
|
||||
private readonly HashSet<object> _activeHosts = new(ReferenceEqualityComparer.Instance);
|
||||
private CancellationTokenSource? _pollCts;
|
||||
private Task? _pollTask;
|
||||
|
||||
@ -113,13 +114,25 @@ public partial class ExperimentConsoleViewModel : ObservableObject
|
||||
LoadCurrentSetpoint = value.Current;
|
||||
}
|
||||
|
||||
public void SetActive(bool active)
|
||||
public void SetActive(object host, bool active)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(host);
|
||||
|
||||
lock (_pollLock)
|
||||
{
|
||||
if (active)
|
||||
{
|
||||
_activeHosts.Add(host);
|
||||
StartPolling();
|
||||
}
|
||||
else
|
||||
{
|
||||
_activeHosts.Remove(host);
|
||||
if (_activeHosts.Count == 0)
|
||||
StopPolling();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task ApplyPower()
|
||||
|
||||
@ -49,6 +49,9 @@ public partial class TestHostViewModel : ObservableObject
|
||||
|
||||
private void UpdateConsoleActive()
|
||||
{
|
||||
Console.SetActive(_isViewActive && SelectedTabIndex == 0);
|
||||
// Identify this host when acquiring/releasing console polling. During a
|
||||
// project switch WPF can load the new host before unloading the old one;
|
||||
// the old host must not stop the shared console on behalf of the new host.
|
||||
Console.SetActive(this, _isViewActive && SelectedTabIndex == 0);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user