ireaper (2)

Ireaper怎么实现只运行一个实例?继续讨论上一个HaveOtherInstance()方法,发现并不是想象的那样

EvenWaitHandle global=new EventWaitHandle(true,EventResetMode.AutoReset,"iReaper")

在运行后会有这样一个事件,导致在新建另一个实例时不会引发异常从而返回true.而是一直进入Catch语句块.

看看Form form = Core.CoreData[CoreDataType.ApplicationForm] as Form;能不能找到一些线索.

目的是分析Core.CoreData返回的到底是什么.

Core这个类如下:

 

   1: public class Core
   2:    {
   3:        static NotifiedDictionary coreData;
   4:  
   5:        /// <summary>
   6:        /// 获取或者设置核心数据
   7:        /// </summary>
   8:        public static NotifiedDictionary CoreData
   9:        {
  10:            get { return Core.coreData; }
  11:            set { Core.coreData = value; }
  12:        }
  13:  
  14:        static Core()
  15:        {
  16:            CoreData = new NotifiedDictionary();
  17:            InitCoreData();
  18:  
  19:        }

其中NotifiedDictionary是一个类:

 

   1: public delegate void OnDataSetEventHandler(CoreDataType Key, object value);
   2:    /// <summary>
   3:    /// 一个支持INotifyPropertyChanged接口的哈西表,用来存储各种全局的
   4:    /// </summary>
   5:    public class NotifiedDictionary:Dictionary<CoreDataType,object>,INotifyPropertyChanged
   6:    {
   7:  
   8:        Dictionary<CoreDataType, PropertyChangedEventArgs> properties =
   9:            new Dictionary<CoreDataType, PropertyChangedEventArgs>();
  10:  
  11:        [MethodImpl(MethodImplOptions.Synchronized)]
  12:        public new void Add(CoreDataType key, object value)
  13:        {
  14:            base.Add(key, value);
  15:            if (properties.ContainsKey(key))
  16:            {
  17:                return;
  18:            }
  19:            else
  20:            {
  21:                properties.Add(key, new PropertyChangedEventArgs(key.ToString()));
  22:            }
  23:        }
  24:  
  25:        /// <summary>
  26:        /// 一个同步的索引器
  27:        /// </summary>
  28:        /// <param name="Key"></param>
  29:        /// <returns></returns>
  30:        
  31:        public new object this[CoreDataType Key]
  32:        {
  33:            [MethodImpl(MethodImplOptions.Synchronized)]
  34:            get
  35:            {
  36:                return base[Key];
  37:            }
  38:  
  39:            [MethodImpl(MethodImplOptions.Synchronized)]
  40:            set 
  41:            {
  42:                base[Key] = value;
  43:                this.InvokeCoreDataTypeNotification(Key);
  44:            }
  45:        }
  46:  
  47:        /// <summary>
  48:        /// 触发指定类型数据的更新信息
  49:        /// </summary>
  52:        {
  50:        /// <param name="Type"></param>
  51:        public void InvokeCoreDataTypeNotification(CoreDataType Type)
  53:            if (PropertyChanged != null)
  54:            {
  55:                this.PropertyChanged(this, properties[Type]);
  56:            }
  57:        }

转载于:https://www.cnblogs.com/symphony2010/archive/2011/07/24/2115494.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值