delegate 多线程
来源:互联网 发布:linux 获取网卡状态 编辑:程序博客网 时间:2024/06/11 00:47
using System;using System.Threading; public class Student{ private int score; public void SetScore(int value) { if (value > 100 || value < 0) { Console.Out.WriteLine("分数不对"); } else { score = value; if (AdviseDelegateInstance!= null) { AdviseDelegateInstance.BeginInvoke(score, new System.AsyncCallback(CallBackMethod), "idior"); } } } private void CallBackMethod(IAsyncResult asyncResult) { string result = AdviseDelegateInstance.EndInvoke(asyncResult); string stateObj=(string)asyncResult.AsyncState; Console.Out.WriteLine("学生{0}收到老师返回的结果/t" + result,stateObj); } public delegate string AdviseDelegate(int score); public AdviseDelegate AdviseDelegateInstance; } public class Teacher{ public string Advise(int score) { Thread.Sleep(3000); if (score < 60) { Console.Out.WriteLine(score + "老师说加油"); return "不及格"; } else { Console.Out.WriteLine(score + "老师说不错"); return "及格"; } }} class MainClass{ [STAThread] private static void Main(string[] args) { Teacher teacher = new Teacher(); Student s = new Student(); s.AdviseDelegateInstance= new Student.AdviseDelegate(teacher.Advise); Console.Out.WriteLine("学生得到50分"); s.SetScore(50); Console.Out.WriteLine("/n学生得到75分"); s.SetScore(75); Console.ReadLine(); }}
- delegate 多线程
- delegate 与 多线程
- c# delegate(委托)与多线程
- C# Delegate(委托)与多线程
- C# Delegate(委托)与多线程
- C# Delegate(委托)与多线程
- C# Delegate/委托 与多线程
- C# Delegate/委托 与多线程
- C# Delegate(委托)与多线程
- C# Delegate(委托)与多线程
- C# Delegate(委托)与多线程
- C# Delegate/委托 与多线程
- C# Delegate(委托)与多线程
- C# 多线程方式 Thread Delegate
- C# Delegate(委托)与多线程
- iphone多线程(NSInvocationOpration) delegate的实现方法
- 3.C#多线程补充(委托Delegate)
- delegate
- vim
- Python 速成培训及其幻灯的编写配置
- ldd3 读书笔记 —— scull 2 运行
- ajax异步
- Linux 休眠和挂起
- delegate 多线程
- ie下span标签浮动换行的简单解决方法
- .Net 2.0 WebService传递参数的问题
- 如何在Red Hat 9 使用YUM
- 实验:用OpenSSL命令行生成证书
- 调用门实战(1)----调用门跳转
- NESI—概念和内涵
- 我来了
- 傅里叶变换的意义