zoukankan      html  css  js  c++  java
  • 单列下添加事件

    单列模式下的对象中事件在注册的时候,若被注册的地方进行多次重复注册(主要是初始化对象时造成)。尤其是通知到窗口的消息。不用系统给的事件,而是自定义委托后的事件

     public delegate void OnSendPrintBarcodeReplyToFormDelegate(object sende,
              FlowDataEventArgs<BatchPrintBarcodesControlServerReply> e);
    
            private OnSendPrintBarcodeReplyToFormDelegate
                _onSendPrintBarcodeReplyToFormDelegateEventHandler;
            /// <summary>
            /// 通知界面事件
            /// </summary>
            public event OnSendPrintBarcodeReplyToFormDelegate OnSendPrintBarcodeReplyToFormDelegateEventHandler
            {
                add
                {
                    //关键部分,如果已经注册过事件,则能防止重复注册  
                    if (_onSendPrintBarcodeReplyToFormDelegateEventHandler == null)
                        _onSendPrintBarcodeReplyToFormDelegateEventHandler += value;
                    else
                    {
                        //先清空后赋值,要不然消息传递到窗体时对界面的相应更改不起作用(可能失去句柄)
    _onSendPrintBarcodeReplyToFormDelegateEventHandler = null;
                        _onSendPrintBarcodeReplyToFormDelegateEventHandler += value;
                    }
                }
                remove
                {
                    _onSendPrintBarcodeReplyToFormDelegateEventHandler -= value;
                }
            }
  • 相关阅读:
    C# Arrays
    C# 类 (12)
    C# 类 (11)
    C# 类 (10)
    常用的HDFS操作
    Java StringTokenizer 类使用方法
    常用HBase操作
    常用Linux命令
    彻底关闭Windows10的更新
    如何将百度坐标转换为国家2000(或WGS84)坐标系?
  • 原文地址:https://www.cnblogs.com/musexiaoluo/p/6673941.html
Copyright © 2011-2022 走看看