• ASP.NET温故而知新学习系列之ASP.NET多线程编程—.NET下的多线程编程Thread中委托的使用(六)


      阅读目录

      一:实例

      一:实例

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

      namespace ThreadDelegate
      class Program
         {
            static void Main(string[] args)
            {
                Thread thread = SimpleThread.CreateThread(new SimpleThread.MyDelegate(User.DelegateMethod), "从小就犯困");
                thread.Start();
                thread.Join(Timeout.Infinite);
                Console.ReadKey();
            }
        }

        class User
        {
            //step2定义一个静态方法
            public static void DelegateMethod(object obj)
            {
                Console.WriteLine("我的名字叫:" + obj);
            }
        }
        
        class SimpleThread
        {
            //step1声明一个委托
            public delegate void MyDelegate(object obj);

              /// <summary>
              /// 创建一个用户类
            /// </summary>
             public class User
             {
                  public object _name;//名字
                  public MyDelegate mydelegate;
                  /// <summary>
                  /// 得到名字
                  /// </summary>
                  public void GetName()
                  {
                      mydelegate(_name);
                  }
             }

             /// <summary>
             /// 创建一个线程
             /// </summary>
             /// <param name="mydelegate"></param>
             /// <param name="name"></param>
             /// <returns></returns>
             public static Thread CreateThread(MyDelegate mydelegate, object name)
             {
                  User user = new User();
                  user._name = name;
                  user.mydelegate = mydelegate;
                  Thread thread = new Thread(user.GetName);
                  return thread;
             }
         }
     }

     

  • 相关阅读:
    Log4net使用指南[转]
    SQL 数据库全库检索
    10款屏幕取色器/颜色拾取工具软件介绍及下载地址[转]
    字符串加密解密函数 (C#) (转)
    C# 读写文本文件乱码解决方案
    C# tips 设置文本框光标的位置[转]
    如何显示数据库中的试题和图形[转]
    [转帖]C#执行SQL脚本,读取XML文件
    使用AnimateWindow API函数实现动画窗体
    雨林木风 Ylmf Linux Y1.5(Ubuntu 9.10)正式发布[转]
  • 原文地址:https://www.cnblogs.com/menglin2010/p/2413535.html
Copyright © 2020-2023  润新知