• 委托与事件


    public abstract class AbstractThread
        {
            Thread thread 
    = null;

            
    public abstract void run();

            
    public void start()
            {
                
    if (thread == null)
                    thread 
    = new Thread(new ThreadStart(run));
                thread.Start();
            }
        }
    public delegate void TimeEventHandler(object obj, TimeEventArgs args); 

        
    public class EventThread : AbstractThread
        {
            
    public EventThread()
            {
                IsAlive 
    = true;
            }

            
    public event TimeEventHandler TimeChanged;

            
    public bool IsAlive { getset; }

            
    public override void run()
            {
                DateTime initi 
    = DateTime.Now;
                
    int h1 = initi.Hour;
                
    int m1 = initi.Minute;
                
    int s1 = initi.Second;
                
    while (IsAlive)
                {
                    DateTime now 
    = DateTime.Now;
                    
    int h2 = now.Hour;
                    
    int m2 = now.Minute;
                    
    int s2 = now.Second;
                    
    if (s2 != s1)
                    {
                        h1 
    = h2;
                        m1 
    = m2;
                        s1 
    = s2;

                        
    //首先建立一个TimeEventArgs对象来保存相关参数,这里是时分秒。
                        TimeEventArgs args = new TimeEventArgs(h2, m2, s2);
                        TimeChanged(
    this, args);
                    }
                    Thread.Sleep(
    1000);
                }


            }
        }

        
    public class TimeEventArgs : EventArgs
        {
            
    private int hour;
            
    private int minute;
            
    private int second;
            
    public TimeEventArgs(int hour, int minute, int second)
            {
                
    this.hour = hour;
                
    this.minute = minute;
                
    this.second = second;
            }
            
    public int Hour
            {
                
    get
                {
                    
    return hour;
                }
            }
            
    public int Minute
            {
                
    get
                {
                    
    return minute;
                }
            }
            
    public int Second
            {
                
    get
                {
                    
    return second;
                }
            }
        }
  • 相关阅读:
    问题——虚拟机连接,查本地DNS,查软件位置,payload生成,检测注册表变化
    nmap命令解释
    SMB扫描,SMTP扫描
    操作系统识别,SNMP扫描
    服务扫描——查询banner信息,服务识别
    nmap之扫描端口(附加hping3隐藏扫描)
    scapy简单用法——四层发现
    转载 界面组装器模式
    设计模式=外观模式
    如何进行自动化测试和手工测试
  • 原文地址:https://www.cnblogs.com/kenter/p/2029868.html
Copyright © 2020-2023  润新知