我有一个 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;
}
}
}
参考 http://www.yoda.arachsys.com/csharp/singleton.html
我的班级过去常常从中级驾驶中收集 GPS 数据。我想要的是在我可以订阅的单例类上创建一个事件?例如。 MyClass.Instance.LocationChanged += ...;
任何帮助将不胜感激。
Mark
有什么问题?
public sealed class Singleton
{
... your code ...
public delegate LocationChangedEventHandler(object sender, LocationChangedEventArgs ea);
public event LocationChangedEventHandler LocationChanged;
private void OnLocationChanged(/* args */)
{
if (LocationChanged != null)
LocationChanged(this, new LocationChangedEventArgs(/* args */);
}
}
public class LocationChangedEventArgs : EventArgs
{
// TODO: implement
}
Call OnLocationChanged
每当你想触发事件时。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)