zoukankan      html  css  js  c++  java
  • C#异步委托等待句柄的使用

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


    namespace AsyncDelegateExam
    {
        delegate int TakeAWhileDelegate(int data,int ms);


        class Program
        {
            static void Main(string[] args)
            {
                TakeAWhileDelegate del = TakeAWhile;
                IAsyncResult ar = del.BeginInvoke(1, 1000, null, null);
                while (true)
                {
                    Console.WriteLine(".");
                    if (ar.AsyncWaitHandle.WaitOne(50,false))
                    {
                        Console.WriteLine("Can Get Result now!");
                        break;
                    }

                }
                int result = del.EndInvoke(ar);
                Console.WriteLine("result:{0}", result);
                Console.Read();
            }


            static int TakeAWhile(int data,int ms)
            {
                Console.WriteLine("TakeAWhile Started!");
                Thread.Sleep(ms);
                Console.WriteLine("TakeAWhile Completed!");
                return ++data;
            }


            
        }
    }



  • 相关阅读:
    【学习笔记】查看CUDA版本
    如果Visual Studio太大,不妨还是用VSCode开发C#项目吧
    Visual Studio npm配置淘宝镜像
    c++读写锁--读者写者问题
    c++内存对象模型--vs2017下的分析,32位
    android作业
    android连接数据库
    android第十周(增删改查)
    android-购物车
    android计算器
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434779.html
Copyright © 2011-2022 走看看