【发布时间】:2010-12-16 23:00:49
【问题描述】:
我有一个使用遵循这种模式的单例类的 Windows Mobile 6.5 (.net cf 3.5):
public sealed class Singleton
{
static readonly Singleton instance=new Singleton();
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static Singleton()
{
}
Singleton()
{
}
public static Singleton Instance
{
get
{
return instance;
}
}
}
我的班级曾经从中间驱动器收集 GPS 数据。我想要的是在我可以订阅的单例类上创建一个事件?例如。 MyClass.Instance.LocationChanged += ...;
任何帮助将不胜感激。
标记
【问题讨论】:
-
小心,任何订阅事件的代码都必须显式地取消订阅它。否则会导致内存泄漏。
标签: c# compact-framework