当前位置:编程学习 > asp >>

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

上一篇:http://www.zzzyk.com/kf/201203/123733.html 


阅读目录
  一:实例
  一:实例
  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>
              /// 得到名字www.zzzyk.com
              /// </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;
         }
     }
 }

  \


每天学习一点点,每天进步一点点 用文字记录工作,用文字记录人生
 

摘自  从小就犯困

补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,