6.7 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | ||
|---|---|---|---|---|---|---|
|
2026-04-16T02:11:43.845066+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | 85046dce961f12c2 |
BusyIndicatorManager
Documentation: BusyIndicatorManager Module
1. Purpose
This module provides a centralized, singleton-based busy indicator management system for WPF applications, enabling multiple components or operations to request and release busy state independently while ensuring the UI reflects a consistent busy status. It decouples the initiation of busy operations (via unique IDs) from the actual display of the busy indicator, which is expected to be bound to the IsBusy and Message properties of the BusyIndicatorManager instance. The xBusyIndicator class serves as the XAML-backed UI control that presumably consumes this manager (though its current implementation is minimal).
2. Public Interface
BusyIndicatorManager (Singleton)
-
public static BusyIndicatorManager Instance { get; }
Thread-safe singleton accessor. Returns the single shared instance ofBusyIndicatorManager. Uses double-checked locking viaSyncRoot. -
public bool IsBusy { get; }
Read-only property indicating whether any busy request is currently active. RaisesPropertyChangedon change (viaNotificationObjectbase). -
public string Message { get; }
Read-only property containing the current busy message. Reflects the message of the last added or active busy request (seeShowBusy/CloseBusybehavior). RaisesPropertyChangedon change. -
public void ShowBusy(int id, string busyMessage)
Registers a new busy request with the givenid. Ifidis new, it adds thebusyMessageto the internal dictionary and setsIsBusy = trueandMessage = busyMessage. Ifidalready exists, it updates the stored message for thatid, and ensuresIsBusy = trueandMessage = busyMessage(i.e., overwrites current message regardless of prior state).
Note: Does not deduplicate or prevent multipleShowBusycalls with the sameid—only updates the message. -
public void CloseBusy(int id)
Removes the busy request identified byid. If no requests remain (busyParameters.Count == 0), setsIsBusy = falseandMessage = "". Otherwise, setsIsBusy = trueandMessage = busyParameters.Last().Value(i.e., the message of the last-enumerated remaining request).
Note: Enumeration order ofDictionary<int, string>is insertion order in .NET, but relying onLast()for priority is fragile and not guaranteed to be intuitive.
xBusyIndicator (UI Control)
-
public xBusyIndicator()
Constructor. CallsInitializeComponent()to load the XAML-defined UI. -
public void Connect(int connectionId, object target)
Currently empty implementation. Presumably intended to associate a UI element (target) with a logical connection ID (connectionId), but no behavior is defined in the source.
3. Invariants
- Singleton uniqueness: Exactly one instance of
BusyIndicatorManagerexists per AppDomain (enforced vialockand null-check). IsBusytruthfulness:IsBusy == trueiffbusyParameters.Count > 0.IsBusy == falseiffbusyParameters.Count == 0.
Messageconsistency:- When
IsBusy == true,Messageequals thebusyMessagestring associated with the last-enumerated entry inbusyParameters. - When
IsBusy == false,Message == string.Empty.
- When
- ID uniqueness per request: Each
idinShowBusy(id, ...)maps to one message inbusyParameters. Reusing anidupdates the message but does not create a new entry.
4. Dependencies
Dependencies of this module:
Microsoft.Practices.Prism.ViewModel.NotificationObject: Base class forBusyIndicatorManager, enabling property change notifications (RaisePropertyChanged).System.Collections.Generic: Used forDictionary<int, string>.System.Linq: Used forbusyParameters.Last()inCloseBusy.- WPF UI framework:
xBusyIndicatorinherits fromSystem.Windows.Controls.UserControl(implied byInitializeComponent()and XAML usage).
Dependencies on this module:
- UI components (not visible in source): Presumably XAML views bind to
BusyIndicatorManager.Instance.IsBusyand.Messageto drive aBusyIndicatorcontrol (e.g., fromXceed.Wpf.Toolkit). xBusyIndicator.xaml: The XAML file forxBusyIndicator(not provided), which likely consumesBusyIndicatorManagerto display the busy state.
5. Gotchas
-
CloseBusymessage selection is arbitrary:busyParameters.Last()uses dictionary enumeration order, which is insertion order in .NET, but this is not documented as a contract. If multiple requests are active, the displayed message may change unexpectedly when an unrelated request is closed.
Example: Requests added in orderid=1,id=2,id=3→ closingid=2changes message to that ofid=3, even ifid=1was the "primary" request. -
No validation on
id:ShowBusyandCloseBusyaccept anyint. Duplicates are allowed (with update semantics), but no error is thrown for invalid IDs. -
Connectmethod is a stub:xBusyIndicator.Connecthas no implementation. Its purpose is unclear—without knowing the intended use ofconnectionIdandtarget, this API is non-functional. -
No thread-safety for
busyParameters: While singleton instantiation is thread-safe, all operations onbusyParameters(e.g.,ContainsKey,Add,Remove,Last) are not synchronized. Concurrent calls toShowBusy/CloseBusyfrom multiple threads may cause race conditions (e.g.,KeyNotFoundException, corrupted dictionary state).
Note: The singleton uses a lock for initialization only. -
Message overwriting on
idreuse: CallingShowBusy(42, "A")thenShowBusy(42, "B")updates the message but does not resetIsBusyif it was alreadytrue. This may be intentional, but could mask bugs if callers assume eachShowBusyis independent. -
Hardcoded property names:
RaisePropertyChanged("IsBusy")uses string literals. No compile-time safety—renaming properties would break binding silently. -
No timeout or cancellation support: Busy state persists indefinitely until
CloseBusy(id)is called. No mechanism to auto-release or cancel long-running requests. -
Xceed.Wpf.Toolkitimported but unused: The namespace is imported inxBusyIndicator.xaml.cs, but noXceed.Wpf.Toolkittypes are referenced in the provided code. May indicate future use or leftover artifact.