Create Event on Singleton Class

后端 未结 2 429
不思量自难忘°
不思量自难忘° 2021-01-28 17:29

I have a Windows Mobile 6.5 (.net cf 3.5) that uses a singleton class which follows this pattern:

public sealed class Singleton
{
    static readonly Singleton in         


        
2条回答
  •  离开以前
    2021-01-28 17:47

    You should just be able to do this as you would an event on any class.

    public event Action LocationChanged;
    

    you can then have a protected virtual method such as:

    protected virtual void OnLocationChanged(EventArgs args)
    {
       if(LocationChanged != null)
       {
         LocationChanged(this, args);
       }
    }
    

    You can fire off your OnLocationChanged method where ever you need too and the event's you've attached will do their thing.

提交回复
热议问题