using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace DelegeteNotes
{
public class NewMailEventArgs : EventArgs
{
private readonly String m_from, m_to, m_subject;
public String From { get { return m_from; } }
public String To { get { return m_to; } }
public String Subject { get { return m_subject; } }
}
internal class MailManager
{
public event Action _onMouseMove;
public event Action OnMouseMove
{
add
{
lock (obj)
{
_onMouseMove += value;
}
}
remove
{
lock (obj)
{
_onMouseMove -= value;
}
}
}
public void Notify()
{
if (_onMouseMove != null)
{
_onMouseMove();
}
}
private event EventHandler<NewMailEventArgs> m_newMail;
private static readonly Object obj = new Object();
private event EventHandler<NewMailEventArgs> NewMail
{
add
{
lock(obj)
{
m_newMail += value;
}
}
remove
{
lock (obj)
{
m_newMail -= value;
}
}
}
static void Main(string[] args)
{
Console.WriteLine(obj.GetHashCode());
MailManager m=new MailManager();
m.OnMouseMove += () => { Console.WriteLine("woca"); };
m.Notify();
m._onMouseMove();
}
}
}
CLR 委托封装 add和remove
最新推荐文章于 2023-07-09 17:50:53 发布