zoukankan      html  css  js  c++  java
  • 委托 事件 多线程 简单例子

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;

    namespace Teseweituo
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    public void print(string s)
    {
    MessageBox.Show(s);
    }

    public delegate void myprint(string s);
    public event myprint myevent;
    private void button4_Click(object sender, EventArgs e)
    {

    Thread t1;
    t1 = new Thread(new ThreadStart(BackgroundProcess));
    t1.Start();

    }
    private void BackgroundProcess()
    {

    myprint mp = new myprint(print);
    print("委托调用");
    myevent += new myprint(print);
    myevent("事件触发调用");

    this.BeginInvoke(myevent, "异步事件调用");
    this.BeginInvoke(new myprint(print), "异步委托调用");
    myevent -= new myprint(print);

    }
    }
    }

  • 相关阅读:
    文件权限
    文件权限
    Nginx SSL/HTTPS 配置
    Nginx SSL/HTTPS 配置
    Nginx SSL/HTTPS 配置
    安装opencv3.3.0方法
    安装opencv3.3.0方法
    安装opencv3.3.0方法
    安装opencv3.3.0方法
    阿里巴巴的体量到底有多大?
  • 原文地址:https://www.cnblogs.com/xiguanjiandan/p/2764009.html
Copyright © 2011-2022 走看看