惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Vercel News
Vercel News
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Schneier on Security
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
博客园 - 司徒正美
NISL@THU
NISL@THU
T
Threat Research - Cisco Blogs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Latest news
Latest news
H
Help Net Security
雷峰网
雷峰网
Spread Privacy
Spread Privacy
Cyberwarzone
Cyberwarzone
Project Zero
Project Zero
Security Latest
Security Latest
Know Your Adversary
Know Your Adversary
人人都是产品经理
人人都是产品经理
P
Privacy & Cybersecurity Law Blog
M
MIT News - Artificial intelligence
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Proofpoint News Feed
U
Unit 42
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
博客园 - 三生石上(FineUI控件)
Stack Overflow Blog
Stack Overflow Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
量子位
C
Cyber Attacks, Cyber Crime and Cyber Security
S
Securelist
S
Security @ Cisco Blogs
T
Threatpost
P
Palo Alto Networks Blog
C
Check Point Blog
V
Vulnerabilities – Threatpost
T
Tailwind CSS Blog
B
Blog RSS Feed
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
P
Proofpoint News Feed
P
Privacy International News Feed
AWS News Blog
AWS News Blog
博客园 - 叶小钗
WordPress大学
WordPress大学

博客园 - tony.zjb

中国市场 IIC GPN14 49美元Android PC驾到!威盛APC初探 C# 16进制与字符串、字节数组之间的转换 什么是RAW数据? s3c6410 SD卡启动的Secure mode Linux常用的 wince进入回收站== 转载:在WinCE中实现Screen Rotation bsp是什么? vc技巧 _stdcall(WINAPI) 与 _cdecl的区别 用C函数来转换Unicode和ANSI文字 - tony.zjb - 博客园 Win32 字符编码 明辨接口实现和虚函数重载的区别 阅读代码 remoting 全新的2008年。。。。。。 vfpConn
异步
tony.zjb · 2008-05-28 · via 博客园 - tony.zjb

一).描述
  先运行个简单的线程示例,认识一下线程
  通过委托调用方法,以及使用AsyncResult判断线程的状态

(二).代码
using System;
using System.Threading;
using System.Runtime.Remoting.Messaging;

namespace 通过委托异步调用方法

 //委托声明(函数签名)
 delegate string MyMethodDelegate();

 class MyClass
 {
  //要调用的动态方法
  public string MyMethod1()
  {
   return "Hello Word1";
  }

  //要调用的静态方法
  public static string MyMethod2()
  {
   return "Hello Word2";
  }
 }
 class Class1
 {
  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main(string[] args)
  {
            MyClass myClass = new MyClass();
   
   //方式1:  声明委托,调用MyMethod1
   MyMethodDelegate d = new MyMethodDelegate(myClass.MyMethod1);
   string strEnd = d();   
   Console.WriteLine(strEnd);

   //方式2:  声明委托,调用MyMethod2 (使用AsyncResult对象调用)
   d = new MyMethodDelegate(MyClass.MyMethod2); //定义一个委托可以供多个方法使用      
   AsyncResult myResult;   //此类封闭异步委托异步调用的结果,通过AsyncResult得到结果.
   myResult = (AsyncResult)d.BeginInvoke(null,null);        //开始调用
   while(!myResult.IsCompleted)  //判断线程是否执行完成
   {
    Console.WriteLine("正在异步执行MyMethod2 .....");
   }
   Console.WriteLine("方法MyMethod2执行完成!");
   strEnd = d.EndInvoke(myResult);      //等待委托调用的方法完成,并返回结果  
   Console.WriteLine(strEnd);
   Console.Read();
  }
 }
}