ireaper (2)
2011-07-24 17:23 symphony2010 阅读(156) 评论(0) 编辑 收藏 举报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: }