021事件详解

事件的应用

  • 实例演示

    • 派生(继承)与扩展(extends)
  • 事件模型的五个组成部分

    • 1.事件的拥有者(event source,对象)T周
    • 2.事件成员(event,成员)
    • 3.事件的响应者(event subscriber,对象)
    • 4.事件处理器(event handler,成员)——本质上是一个回调方法
    • 5.事件订阅——把事件处理器与事件关联在一起,本质上是一种以委托类型为基础的约定”
  • 注意

    • 事件处理器是方法成员
    • 挂接事件处理器的时候,可以使用委托实例,也可以直接使用方法名这是个“语法糖。
    • 事件处理器对事件的订阅不是随意的,匹配与否由声明事件时所使用的委托类型来检事件可以同步调用也可以异步调用

 

简单的例子:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace demo2
{
    public delegate double Calc(double x, double y);

    class Program
    {
        static void Main(string[] args)
        {
            Timer timer = new Timer();//事件拥有者
            timer.Interval = 1000;
            Boy boy = new Boy();//事件响应者
            Girl girl = new Girl();
            timer.Elapsed += boy.Action;//时间订阅
            timer.Elapsed += girl.Action;
            timer.Start();
            Console.ReadLine();
        }
    }

    class Boy
    {
        internal void Action(object sender, ElapsedEventArgs e)//事件处理器
        {
            Console.WriteLine("Jump");
        }
    }

    class Girl
    {
        internal void Action(object sender, ElapsedEventArgs e)//事件处理器
        {
            Console.WriteLine("Sing!");
        }
    }
}

 

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace demo2
{
    public delegate double Calc(double x, double y);

    class Program
    {
        static void Main(string[] args)
        {
            Form form = new Form();//事件拥有着
            Controller controller = new Controller(form);//事件响应者
            form.ShowDialog();
        }
    }

    class Controller
    {
        private Form Form;

        public Controller(Form form)
        {
            this.Form = form;
            this.Form.Click += this.FormClicked;//订阅 Click事件成员
        }

        private void FormClicked(object sender, EventArgs e)//事件处理器
        {
            this.Form.Text = DateTime.Now.ToString();
        }
    }
}

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace demo2
{
    public delegate double Calc(double x, double y);

    class Program
    {
        static void Main(string[] args)
        {
            MyForm form = new MyForm();
            form.Click += form.FormClicked;
            form.ShowDialog();
        }
    }

    class MyForm : Form
    {
        internal void FormClicked(object sender, EventArgs e)
        {
            this.Text = DateTime.Now.ToString();
        }
    }
}

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace demo2
{
    public delegate double Calc(double x, double y);

    class Program
    {
        static void Main(string[] args)
        {
            MyForm form = new MyForm();
            form.ShowDialog();
        }
    }

    class MyForm : Form
    {
        private TextBox textBox;
        private Button button;

        public MyForm()
        {
            this.textBox = new TextBox();
            this.button = new Button();
            this.Controls.Add(this.button);
            this.Controls.Add(this.textBox);
            this.button.Click += this.buttonClicked;
            this.button.Text = "Say Hello";
            this.button.Top = 30;
        }

        private void buttonClicked(object sender, EventArgs e)
        {
            this.textBox.Text = "Hello World!!!!!!!!!!!!!!!!!";
        }
    }
}

 

???

 

转载于:https://www.cnblogs.com/YiShen/p/9898318.html

内容概要:本文档详细介绍了基于MATLAB实现的无人机三维路径规划项目,核心算法采用蒙特卡罗树搜索(MCTS)。项目旨在解决无人机在复杂三维环境中自主路径规划的问题,通过MCTS的随机模拟与渐进式搜索机制,实现高效、智能化的路径规划。项目不仅考虑静态环境建模,还集成了障碍物检测与避障机制,确保无人机飞行的安全性和效率。文档涵盖了从环境准备、数据处理、算法设计与实现、模型训练与预测、性能评估到GUI界面设计的完整流程,并提供了详细的代码示例。此外,项目采用模块化设计,支持多无人机协同路径规划、动态环境实时路径重规划等未来改进方向。 适合人群:具备一定编程基础,特别是熟悉MATLAB和无人机技术的研发人员;从事无人机路径规划、智能导航系统开发的工程师;对MCTS算法感兴趣的算法研究人员。 使用场景及目标:①理解MCTS算法在三维路径规划中的应用;②掌握基于MATLAB的无人机路径规划项目开发全流程;③学习如何通过MCTS算法优化无人机在复杂环境中的飞行路径,提高飞行安全性和效率;④为后续多无人机协同规划、动态环境实时调整等高级应用打下基础。 其他说明:项目不仅提供了详细的理论解释和技术实现,还特别关注了实际应用中的挑战和解决方案。例如,通过多阶段优化与迭代增强机制提升路径质量,结合环境建模与障碍物感知保障路径安全,利用GPU加速推理提升计算效率等。此外,项目还强调了代码模块化与调试便利性,便于后续功能扩展和性能优化。项目未来改进方向包括引入深度强化学习辅助路径规划、扩展至多无人机协同路径规划、增强动态环境实时路径重规划能力等,展示了广阔的应用前景和发展潜力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值