fix: handle login window shutdown

master
tayttt 3 days ago
parent cfc1638d85
commit 6d5a72b849

@ -28,19 +28,54 @@ namespace Txgy.EWS.Client.Common.Helpers
//添加Visual
public void AddVisual(Visual visual)
{
visuals.Add(visual);
InvokeOnDispatcher(() =>
{
if (visual == null)
{
return;
}
Application.Current.Dispatcher.Invoke(() => base.AddVisualChild(visual));
Application.Current.Dispatcher.Invoke(() => base.AddLogicalChild(visual));
visuals.Add(visual);
base.AddVisualChild(visual);
base.AddLogicalChild(visual);
});
}
//删除Visual
public void RemoveVisual(Visual visual)
{
visuals.Remove(visual);
InvokeOnDispatcher(() =>
{
if (visual == null)
{
return;
}
if (!visuals.Remove(visual))
{
return;
}
base.RemoveVisualChild(visual);
base.RemoveLogicalChild(visual);
});
}
private void InvokeOnDispatcher(Action action)
{
var dispatcher = Dispatcher;
if (dispatcher == null || dispatcher.HasShutdownStarted || dispatcher.HasShutdownFinished)
{
return;
}
if (dispatcher.CheckAccess())
{
action();
return;
}
Application.Current.Dispatcher.Invoke(()=>base.RemoveVisualChild(visual));
Application.Current.Dispatcher.Invoke(() => base.RemoveLogicalChild(visual));
dispatcher.Invoke(action);
}
//命中测试

@ -611,7 +611,7 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
//InitEventList();
this._ea.GetEvent<UpdateEventFrequencyEvent>().Subscribe(u =>
{
Application.Current.Dispatcher.Invoke(new System.Action(() =>
InvokeOnDispatcher(() =>
{
ListEventFre.Add(new ObservableValue(u));
EventFrequencyCount = u;
@ -621,12 +621,12 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
}
EventFreLabels.Add(DateTime.Now.ToString("HH:mm"));
EventFreMaxY = (int)(ListEventFre.Max(le => le.Value) + 4);
}));
});
});
//最后预警事件
this._ea.GetEvent<UpdateLastAlarmEvent>().Subscribe(u =>
{
Application.Current.Dispatcher.Invoke(new System.Action(() =>
InvokeOnDispatcher(() =>
{
LastAlarmEventEnergy = u.Energy;
ListEnergy.Add(new ObservableValue(u.Energy));
@ -639,7 +639,7 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
//int domainFreq = rnd.Next(15, 60);
//LastAlarmEventDominFreq = domainFreq;
//ListDominantFreq.Add(new ObservableValue(domainFreq));
}));
});
});
//事件主频
this._ea.GetEvent<UpdateEventDominFreqMessage>().Subscribe(u =>
@ -664,7 +664,7 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
//从接收事件列表中删除超过指定时间范围的数据
var timeoutReceivedEvents = ReceviedEvents.Where(re =>
(DateTime.Now - DateTime.Parse(re.EventTime)).TotalHours >= GlobalConfig.DataLookbackHours).ToArray();
_dispatcher.Invoke(new System.Action(() =>
InvokeOnDispatcher(() =>
{
if (timeoutReceivedEvents.Length > 0)
{
@ -674,12 +674,12 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
ReceviedEvents.Remove(dg);
}
}
}));
});
}
_dispatcher.Invoke(new System.Action(() =>
InvokeOnDispatcher(() =>
{
ReceviedEvents.Insert(0, gier);
}));
});
//ReceivedEvents = new ObservableCollection<GridItemEventResult>();
//AlarmEvents = new ObservableCollection<GridItemEventResult>();
@ -692,7 +692,7 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
{
var timeoutAlarmEvents = AlarmEvents.Where(re =>
(DateTime.Now - DateTime.Parse(re.EventTime)).TotalHours >= GlobalConfig.DataLookbackHours).ToArray();
_dispatcher.Invoke(new System.Action(() =>
InvokeOnDispatcher(() =>
{
if (timeoutAlarmEvents.Length > 0)
{
@ -702,18 +702,34 @@ namespace Txgy.EWS.Client.PageModule.ViewModels
AlarmEvents.Remove(dg);
}
}
}));
});
}
_dispatcher.Invoke(new System.Action(() =>
InvokeOnDispatcher(() =>
{
AlarmEvents.Insert(0, gier);
}));
});
//ReceivedEvents = new ObservableCollection<GridItemEventResult>();
//AlarmEvents = new ObservableCollection<GridItemEventResult>();
});
}
private void InvokeOnDispatcher(System.Action action)
{
if (action == null || _dispatcher == null || _dispatcher.HasShutdownStarted || _dispatcher.HasShutdownFinished)
{
return;
}
if (_dispatcher.CheckAccess())
{
action();
return;
}
_dispatcher.Invoke(action);
}
private void ClearWarningData()
{
AlarmEvents.Clear();

@ -32,6 +32,8 @@ namespace Txgy.EWS.Client.Start
/// </summary>
public partial class App : PrismApplication
{
private bool _loginSucceeded;
public App()
{
// 日志Log4Net初始化
@ -62,13 +64,25 @@ namespace Txgy.EWS.Client.Start
{
var config = BusinessConfigManager.Current;
GlobalConfig.InitializeRuntimeSettings(config.Runtime);
GlobalConfig.ReadConfig();
//Debug.WriteLine(GlobalConfig.LoadDataTimeLenMins);
//Debug.WriteLine(GlobalConfig.DataCacheTimeLenMins);
_loginSucceeded = Container.Resolve<LoginView>().ShowDialog() == true;
if (!_loginSucceeded)
{
Shutdown();
return null;
}
return Container.Resolve<MainWindow>();
}
protected override void InitializeShell(Window shell)
{
GlobalConfig.ReadConfig();
if (!_loginSucceeded || shell == null)
{
return;
}
//if (GlobalData.IsDesign)
//{
// base.InitializeShell(shell);
@ -76,17 +90,8 @@ namespace Txgy.EWS.Client.Start
//else
{
//GlobalConfig.ReadConfig();
// 通信容器来获取对象 可以进行相关对象的注入
if (Container.Resolve<LoginView>().ShowDialog() == false)
{
//GlobalConfig.ReadConfig();
Application.Current?.Shutdown();
}
else
{
//CommonLogHelper.Debug("====Start=====>");
base.InitializeShell(shell);
}
//CommonLogHelper.Debug("====Start=====>");
base.InitializeShell(shell);
}
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)

@ -45,7 +45,7 @@ namespace Txgy.EWS.Client.Start.Views
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
this.DialogResult = false;
}
}
}

Loading…
Cancel
Save