• C#用委托来动态显示日期和时间


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace _01测试委托与事件
    {
    
        public delegate void DeShowTime();
    
     
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
    
                Thread thread = new Thread(ShowTime);
                thread.IsBackground = true;
                thread.Start();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                Control.CheckForIllegalCrossThreadCalls = false;
            }
    
            public void ShowTime()
            { 
                while (true)
                {
                    //Lambda表达式
                    //DeShowTime dst = () =>
                    //{
                    //    textBox1.Text = "当前时间:" + DateTime.Now.ToString();
                    //};
    
                    //匿名函数委托
                    DeShowTime dst = delegate
                    {
                        textBox1.Text =  DateTime.Now.ToString();
                        toolStripStatusLabel1.Text = "当前时间: " + DateTime.Now.ToString();
                    };
    
                    dst();
                    Thread.Sleep(1000);
                }
            }
    
        }
    }
    

      

  • 相关阅读:
    Redis之数据持久化RDB与AOF
    linux命令
    路由选择协议
    三次握手+滑动窗口
    JSP的文件上传
    JSP的会话(Session)跟踪
    JSP的Cookie处理
    JSP的过滤器
    JSP的表单处理
    JSP中HTTP状态码
  • 原文地址:https://www.cnblogs.com/nymz/p/14153736.html
Copyright © 2020-2023  润新知