【发布时间】:2021-07-20 11:32:08
【问题描述】:
关于单例实现的其他问题的答案表明构造函数对于单例类应该是私有的。但是从Windows.UI.Xaml.Application 派生的UWP 主App 单例类有一个公共构造函数。 VS为其生成的XML文档说:
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
当我尝试在鼠标事件上创建第二个实例时,我得到了
灾难性故障(HRESULT 异常:0x8000FFFF (E_UNEXPECTED))
那么为什么构造函数是公开的,以及如何实现单例以强制只存在一个 App 实例?
【问题讨论】: