refactor: 插件窗体由 static 单例状态改为实例字段(对齐 TextViewer)
将 10 个 CycleGUI 窗体/管理器从进程级 static 单例状态改为实例字段 + 实例方法, 消除本地端/Web 端共享同一可变状态的隐患(对齐 TextViewer 正例)。 每个类保留一个 private static _instance 单实例持有者;静态入口 Open()/OpenViewer() 与实例 Show() 均转发到该实例,调用方零改动、单实例“置前”行为不变。 涉及:ChargeStationManagementForm、ChargeStrategyConfigForm、CommunicationMonitorForm、 AlarmConfigManagementForm、ButtonBoxManager、DoorManager、DoorMonitor、 LoopViewer、DeliveryViewer、TrafficInterlockViewer。 构建:dotnet build StandardScene.sln --no-incremental → 0 错误,30 警告(与基线一致,无新增)。
This commit is contained in:
@@ -28,26 +28,30 @@ namespace StandardScene.Chained
|
||||
private const int OverdueMinutesThreshold = 10000; // 约 7 天视为超时
|
||||
private const string TableId = "delivery-task-list";
|
||||
|
||||
private static readonly HttpClient SharedHttpClient = new HttpClient();
|
||||
private readonly HttpClient SharedHttpClient = new HttpClient();
|
||||
/// <summary>超时任务整行底色(深色主题下的暗红,醒目但不刺眼)。</summary>
|
||||
private static readonly Color OverdueRowColor = Color.FromArgb(255, 90, 36, 36);
|
||||
private readonly Color OverdueRowColor = Color.FromArgb(255, 90, 36, 36);
|
||||
|
||||
private static Panel _panel;
|
||||
private static bool _showFinished = true; // 显示已完成任务
|
||||
private static bool _showAbolished = true; // 显示废止任务(Error / Canceled / Terminated)
|
||||
private Panel _panel;
|
||||
private bool _showFinished = true; // 显示已完成任务
|
||||
private bool _showAbolished = true; // 显示废止任务(Error / Canceled / Terminated)
|
||||
|
||||
// 渲染快照:由后台线程按 FlushInterval 刷新,渲染线程只读引用;锁/文件 IO 绝不放在渲染线程,避免界面卡死。
|
||||
private static volatile List<Delivery> _snapshot = new List<Delivery>();
|
||||
private static volatile bool _refreshing;
|
||||
private static DateTime _lastFlush = DateTime.MinValue;
|
||||
private static readonly TimeSpan FlushInterval = TimeSpan.FromSeconds(1);
|
||||
private static volatile string _status = "";
|
||||
private volatile List<Delivery> _snapshot = new List<Delivery>();
|
||||
private volatile bool _refreshing;
|
||||
private DateTime _lastFlush = DateTime.MinValue;
|
||||
private readonly TimeSpan FlushInterval = TimeSpan.FromSeconds(1);
|
||||
private volatile string _status = "";
|
||||
|
||||
/// <summary>打开(或置前)任务管理面板。兼容原 <c>new DeliveryViewer().Show()</c> 调用方式。</summary>
|
||||
public void Show() => Open();
|
||||
|
||||
/// <summary>打开(或置前)任务管理面板。</summary>
|
||||
public static void Open()
|
||||
public static void Open() => (_instance ??= new DeliveryViewer()).OpenCore();
|
||||
|
||||
private static DeliveryViewer _instance;
|
||||
|
||||
private void OpenCore()
|
||||
{
|
||||
if (_panel != null)
|
||||
{
|
||||
@@ -127,14 +131,14 @@ namespace StandardScene.Chained
|
||||
});
|
||||
}
|
||||
|
||||
private static bool IsOverdue(Delivery dd) =>
|
||||
private bool IsOverdue(Delivery dd) =>
|
||||
(DateTime.Now - dd.CreateTime).TotalMinutes > OverdueMinutesThreshold;
|
||||
|
||||
/// <summary>
|
||||
/// 渲染线程调用:到达刷新间隔且无在途刷新时,<b>在后台线程</b>重新拉取任务快照(超时任务置顶)。
|
||||
/// 业务侧的锁与文件 IO 一律放到后台,渲染线程只读 <see cref="_snapshot"/> 引用,避免界面卡死。
|
||||
/// </summary>
|
||||
private static void EnsureSnapshotFresh()
|
||||
private void EnsureSnapshotFresh()
|
||||
{
|
||||
if (_refreshing) return;
|
||||
if (DateTime.Now - _lastFlush < FlushInterval) return;
|
||||
@@ -165,14 +169,14 @@ namespace StandardScene.Chained
|
||||
});
|
||||
}
|
||||
|
||||
private static string SafeSiteName(int siteId)
|
||||
private string SafeSiteName(int siteId)
|
||||
{
|
||||
try { return SimpleLib.GetSite(siteId)?.name ?? ""; }
|
||||
catch { return ""; }
|
||||
}
|
||||
|
||||
/// <summary>将任务标记为已取消(Canceled)。</summary>
|
||||
private static void MarkDeliveryCanceled(Delivery d)
|
||||
private void MarkDeliveryCanceled(Delivery d)
|
||||
{
|
||||
if (d == null) return;
|
||||
lock (d.SyncStatus)
|
||||
@@ -187,7 +191,7 @@ namespace StandardScene.Chained
|
||||
/// 当 clearCarForChange=true 时,仅当状态为 Suspended 或 Waiting 且未处于放货阶段时,
|
||||
/// 才会清空 UsingCar 并返回 true;否则返回 false。
|
||||
/// </summary>
|
||||
private static bool MarkDeliveryWaiting(Delivery d, bool clearCarForChange)
|
||||
private bool MarkDeliveryWaiting(Delivery d, bool clearCarForChange)
|
||||
{
|
||||
if (d == null) return false;
|
||||
lock (d.SyncStatus)
|
||||
@@ -217,7 +221,7 @@ namespace StandardScene.Chained
|
||||
}
|
||||
}
|
||||
|
||||
private static void ResendDelivery(string taskCode)
|
||||
private void ResendDelivery(string taskCode)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -247,7 +251,7 @@ namespace StandardScene.Chained
|
||||
}
|
||||
}
|
||||
|
||||
private static void CancelDelivery(string taskCode)
|
||||
private void CancelDelivery(string taskCode)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -286,7 +290,7 @@ namespace StandardScene.Chained
|
||||
}
|
||||
}
|
||||
|
||||
private static void ChangeCarResendDelivery(string taskCode)
|
||||
private void ChangeCarResendDelivery(string taskCode)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user